
On 14/09/2012 2:24 PM, Andrew Sandoval wrote:
On 14/09/2012 11:12 AM, Andrey Semashev wrote:
typedef raii< HANDLE, &CloseHandle > auto_handle;
class my_class { auto_handle m_h; };
This doesn't look like a part of Boost.ScopeExit anymore.
I could make a car into an airplane and it's not a car anymore.
This is quite clever but limited.
How so? I use my RAII class like that all of the time, and it does exactly what is needed. It guarantees I'll never forget to put the CloseHandle into the destructor. In fact, most of the time it means I don't need destructors anymore.
Oh, it's limited because you can't include any state in the deallocation: void youLikeThis(bool doYou,Handle h); boost::scope_guard OMGANAME(youLikeThis,true,handle); Not possible if everything is encoded in the type. Sohail