Boost logo

Boost :

Subject: Re: [boost] [scope_exit] can MSVC lambdas capture data members?
From: lcaminiti (lorcaminiti_at_[hidden])
Date: 2012-03-14 15:55:46

Nathan Ridge wrote
> GCC 4.5 is in error to allow that. 4.7 does not allow it.
> The correct way to use a data member in the lambda is to capture "this",
> and then
> access the member via "this->member" inside the lambda.

OK, thanks. This is a problem for implementing ScopeExit using lambdas on
C++11 because the following code:

struct world {
    void add_person(person const& a_person) {
        bool commit = false;

        SCOPE_EXIT( (&commit) (&persons_) ) {
            if(!commit) persons_.pop_back();

        commit = true;

    std::vector<person> persons_;

Works with the current implementation of ScopeExit that does not use lambdas
but it will no longer compile with the implementation of ScopeExit that uses
lambdas. Therefore, the lambda implementation of ScopeExit cannot be
backward compatible... I will discuss this issue with ScopeExit's main
author Alexander Nasonov but this might mean that ScopeExit will never be
implemented internally using lambdas, not even on C++11 compilers.


View this message in context:
Sent from the Boost - Dev mailing list archive at

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