Closed svart-riddare closed 10 months ago
To achieve the expected outcome you need to use reset(NULL) or use unique_ptr for FILE*
There is more generic "empty" state that ist used.
However, I abandoned generic unique_resource and scope guards, in favor of recommending a per resource implementation of a manager class providing a better abstraction.
See my talks "What Classes we design and how"
Thank you for your quick answer, the example I gave was only to support my comment about the fact that once reset()
has been called at least once, we are unable to know whether the object contains somethig valid or not.
As I understand from your comment and the corresponding sequence in your talk, std::experimental::unique_resource
may never make it to the std
namespace, so I will stop using it.
Using
std::experimental::unique_resource
, I stumbled upon an unexpected behavior of thereset()
function that I can mostly state asreset()
does not reset the owned resource.Building upon one of your code sample:
Once
reset()
has been called, there is no way to know the state of the resource, as there is nooperator!
(oris_valid()
) member function for example.I would have exepected to be able to retrieve this information, either because
reset()
would have restored the resource to it's default value (i.e.RESOURCE = {}
when possible) either by having a member function to check whether the return value ofget()
is valid or not.