
Peter Dimov wrote:
Eric Niebler:
Lambda and phoenix differ as to whether local variables are captured by value or by reference (phoenix always captures by value, lambda tries to guess what you intend based on usage).
Are you sure that
int v[] = { 1, 2, 3 }; std::for_each( v, v + 3, std::cout << arg1 << std::endl );
captures std::cout by value? :-)
OK, OK, you got me. Even for Phoenix, the rules are not simple. Phoenix captures by value *when it can* (except for arrays, which are by reference, I think), or when the user specifies by-ref with phoenix::ref. But the decision is based on object's type, not on how the object is used in the expression, as it is with boost.lambda. Consider that with boost.lambda: int ii = 0; ii += _1; // ii captured by reference here ... _1 += ii; // ... but ii captured by value here -- Eric Niebler BoostPro Computing http://www.boostpro.com