|
Boost : |
Subject: [boost] [scope_exit] improvements
From: Lorenzo Caminiti (lorcaminiti_at_[hidden])
Date: 2012-01-13 18:00:54
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/index.html
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
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk