Boost logo

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:

1) It is possible to use variadic macros on compilers that support them:

int r = 0, v = 0;
    r = v;

To support compilers without variadics and for backward compatibility
with previous ScopeExit versions, all macros also accepts

BOOST_SCOPE_EXIT( (&r) (v) ) {
    r = v;

2) It is possible to capture no variable using `void`:

    std::cout << "cout is a global variable << std::endl;

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);

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);

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.


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