
Le 14/09/12 21:12, Sohail Somani a écrit :
On 14/09/2012 2:58 PM, Andrew Sandoval wrote:
True, but that is why I was proposing two RAII classes. One that is limited and uses only static values for the deleter function and the no-delete value, and another that is much more open including state (RAIIFunction) because you can use bind with it, and lambda's that provide any needed state.
Ok, I guess you like the one with it encoded in the type. I can see its value.
Regarding the second kind:
https://github.com/ryppl/boost-svn/blob/master/boost/scope_exit.hpp#L615
Yes, it's already there but hidden in aux or detali or something.
operator= is a more general dismiss().
So just making it public would be great. I don't like that the destructor checks for f_ in the preceding link.
template<> struct guard<void> { ~guard() { if(f_) f_(); } template<typename Lambda> void operator=(Lambda f) { f_ = f; } private: boost::function<void (void)> f_; }; And I don't know if the assignment operator should be exposed to the user, even if it could have no cost. Anyway the current implementation could require that the parameter should be Callable. The null pattern should be applied there and assigning a lambda that do nothing will avoid the check. BTW, couldn't the cost of boost::function be reduced using the reference to a base class technique used in multi_index/detail/scope_guard.hpp and described in Alexandrescu, A., Marginean, P.:"Generic<Programming>: Change the Way You Write Exception-Safe Code - Forever", C/C++ Users Jornal, Dec 2000, http://www.drdobbs.com/184403758 Best, Vicente