|
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;
persons_.push_back(a_person);
SCOPE_EXIT( (&commit) (&persons_) ) {
if(!commit) persons_.pop_back();
}
commit = true;
}
private:
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.
Thanks.
--Lorenzo
-- View this message in context: http://boost.2283326.n4.nabble.com/boost-scope-exit-can-MSVC-lambdas-capture-data-members-tp4472788p4472959.html Sent from the Boost - Dev mailing list archive at Nabble.com.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk