Boost logo

Boost :

From: Philippe Vaucher (philippe.vaucher_at_[hidden])
Date: 2006-11-27 11:56:26

FWIW, another interface could be a class like :

// untested
class scope_guard

     typedef boost::function<void()> func_type;

     explicit scope_guard()

     explicit scope_guard(const func_type& f)

         for(int i = 0; i < m_functions.size(); ++i)

     void add_function(const func_type& f)

     // Could be used to cancel something
     void clear()


     std::vector<func_type> m_functions;


This, used along with boost::bind would make your example become smth like :

glob_t result_glob;
scope_guard guard(boost::bind(&globfree, &result_glob));
/* throw or return here */

And you could add more than one function call to do with the add_function()
member... of course it's more limited than what your interface offers, but I
think the idea is worth mentionning.

Credits goes to Eelis (irc) for the idea.


Boost list run by bdawes at, gregod at, cpdaniel at, john at