I created a lambda expression inside my std::for_each call.
In it there is code like this one, but I have building error telling me that
error: expected primary-expression before ‘return’ error: expected `]' before ‘return’
In my head I think that boost-lambda works mainly with functors, so since return statement it isn’t like that, calling it doesn’t work.
Do you know what it is and how to fix it?
Thanks
AFG
namespace bl = boost::lambda; int a, b; bl::var_type::type a_( bl::var( a ) ); bl::var_type::type b_( bl::var( b ) ); std::for_each( v.begin(), v.end(), ( // ..do stuff here if_( a_ > _b_ ) [ std::cout << _1, return ] ));
You cannot use
returninstruction inside lambda expression. Use constructions likeif_then_else_return. They offer syntax that allows producing results.But in your case
returnis not even required, just throw it away.