c++ - Is there an idomatic way to return a pointer that optionally owns its value -


I have a function named that path, keeps a look and gives the corresponding value an indicator. Sometimes the price stays in a stable cache, sometimes it is calculated and made on the fly.

Therefore, sometimes it takes ownership to make calls and after reading it, the object is required to be removed, and sometimes it does not. I am thinking, is there anything with which I will wrap this pointer so that the caller can be automatically freed from the required form?

I was thinking that I might be able to use a unique PTR, but the deleter part of the type, how can I return the same type which sometimes does and sometimes Does not really destroy. In fact, for a value created inside a solution function, a normal std:

can return, and with each other the empty deliler for the value in the map.

You can see that both the use cases do not require any action from the calling code and are completely transparent.

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -