[scope_exit] improvements

Hello all, I've been working with Alex to make the following improvements to Boost.ScopeExit (as they were discussed during Boost.Local's review). The update docs: https://svn.boost.org/svn/boost/sandbox/closure/libs/scope_exit/doc/html/ind... 1) It is possible to use variadic macros on compilers that support them: int r = 0, v = 0; BOOST_SCOPE_EXIT(&r, v) { r = v; } BOOST_SCOPE_EXIT_END To support compilers without variadics and for backward compatibility with previous ScopeExit versions, all macros also accepts pp-sequences: BOOST_SCOPE_EXIT( (&r) (v) ) { r = v; } BOOST_SCOPE_EXIT_END 2) It is possible to capture no variable using `void`: BOOST_SCOPE_EXIT(void) { std::cout << "cout is a global variable << std::endl; } BOOST_SCOPE_EXIT_END This same syntax works on compilers with and without variadics. 3) From within member functions, it is possible to capture the object this using `this_`: BOOST_SCOPE_EXIT(&r, v, this_) { r = this_->f(v); } BOOST_SCOPE_EXIT_END On C++11, you can also (but you don't have to) use `this`: BOOST_SCOPE_EXIT(&r, v, this) { // C++11 only. r = this->f(v); } BOOST_SCOPE_EXIT_END 4) On C++11, you can (but you don't have to) use `;` instead of BOOST_SCOPE_END. 5) On C++11, there is an additional macro that allows to capture all variables using lambda-style `&` or `=`: BOOST_SCOPE_EXIT_ALL(&, v, this) { // C++11 only. r = this->f(v); }; Or equivalently: BOOST_SCOPE_EXIT_ALL(=, &r) { // C++11 only. r = this->f(v); }; I still have to move these changes from the sandbox into trunk. Comments are welcome. Thanks, --Lorenzo

lcaminiti wrote
Hello all,
I've been working with Alex to make the following improvements to Boost.ScopeExit (as they were discussed during Boost.Local's review).
The update docs: https://svn.boost.org/svn/boost/sandbox/closure/libs/scope_exit/doc/html/ind...
I still have to move these changes from the sandbox into trunk. Comments are welcome.
Glad to see Lorenzo that you have reached (you and Alex) to adapt all the improvements of Boost.Local to Boost.ScopedExit. Just say waiting for this to be in a boost release :) Vicente -- View this message in context: http://boost.2283326.n4.nabble.com/scope-exit-improvements-tp4293674p4296894... Sent from the Boost - Dev mailing list archive at Nabble.com.
participants (2)
-
Lorenzo Caminiti
-
Vicente Botet