Boost logo

Boost :

From: Gary Powell (powellg_at_[hidden])
Date: 2002-02-07 11:08:20



"for_each(v.begin(), v.end(), _1 = bind(foo, _1));"

'for_each' is a non-mutating algorithm. 'transform' is better for this

That 'for_each' is non-mutating is unfortunate because

"for_each(v.begin(), v.end(), _1 += bind(foo, _1)); "
generates better code than

"transform(v.begin(), v.end(), v.begin(), _1 + bind (foo, _1) ); "
for complex types which have overloaded "+=" operators, and for poor
compilers for native types as well.

My guess is that 'for_each' being labled 'non-mutating' was done without
the consideration that a lambda library would come along and allow code
to be written like this.


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