
Aleksey Gurtovoy wrote:
Joel writes:
write a lambda expression that accepts:
1. a 2-dimensional container (e.g. vector<vector<int> >) 2. a container element (e.g. int)
and pushes-back the element to each of the vector<int>.
Solution:
for_each(_1, lambda(_a = _2) [ push_back(_1, _a) ] )
Since we do not have access to the arguments of the outer scopes beyond the lambda-body, we introduce a local variable _a that captures the second outer argument: _2. Hence: _a = _2. This local variable is visible inside the lambda scope.
Any particular reason why you decided against implicit scoping along the lines of
for_each( _1, push_back(_1, outer(_2)) )
Actually, both solutions are orthogonal. I still have the code for "outer". I just don't have it documented yet. Regards, -- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net