From: Maxim Yegorushkin on 9 Aug 2006 08:34 Buster wrote: [] > To follow up with the previous posts, the ones > suggested weren't exactly what I was looking for > because they require a hard-to-specify local > variable: > > scoped_guard<???> g = make_guard(boost::bind(function, arg1, arg2)); > > whereas all I wanted to write was: > > scoped_guard g = ... > > If I've misunderstood, I'd appreciate the clarification. Please look at the code more closely. Note the line: typedef const detail::scope_guard_base& scope_guard; This line makes it possible to write scoped_guard g = make_guard(boost::bind(function, arg1, arg2)); You don't have to specify template arguments. [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Peter Dimov on 9 Aug 2006 10:16 Buster wrote: > To follow up with the previous posts, the ones > suggested weren't exactly what I was looking for > because they require a hard-to-specify local > variable: > > scoped_guard<???> g = make_guard(boost::bind(function, arg1, arg2)); > > whereas all I wanted to write was: > > scoped_guard g = ... class scoped_guard { public: template<class F> explicit scoped_guard( F f ): f_( f ) { } ~scoped_guard() { if( f_ ) f_(); } void release() { f_.clear(); } private: boost::function< void() > f_; scoped_guard( scoped_guard const & ); scoped_guard & operator=( scoped_guard const & ); }; [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Buster on 9 Aug 2006 13:35 Maxim Yegorushkin wrote: > > Please look at the code more closely. Note the line: > > typedef const detail::scope_guard_base& scope_guard; > > This line makes it possible to write > > scoped_guard g = make_guard(boost::bind(function, arg1, arg2)); > > You don't have to specify template arguments. Way cool. I'd forgotten about that bit of trickery. It even calls the function object's destructor. [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
First
|
Prev
|
Pages: 1 2 Prev: UTF8 and std::string Next: Callback-related libraries and terminology |