
Does a utility like the following already exist in boost? If so, what is it called? If not, is there interest in adding it? template < typename Function > struct free_on_error { private: Function function_; bool reset_; public: free_on_error ( Function function ) : function_ ( function ), reset_ ( true ) { } ~ free_on_error ( ) { if ( reset_ ) { function_ ( ); } } void discard ( ) { reset_ = false; } }; This would be used to make certain operations exception safe. For example: A * foo ( ) { A * a = new A ( ); free_on_error < BOOST_TYPEOF ( lambda::bind ( delete _1, a ) ) > release ( lambda::bind ( delete _1, a ) ); a->DoSomethingThatMightThrow ( ); release.discard ( ); return a; } (my experience with lambda is minimal, so I'm not sure that delete _1 creates a valid lambda functor, but you get the idea) -Jason