|
Boost : |
From: Gary Powell (powellg_at_[hidden])
Date: 2002-02-07 11:08:20
//---------
4.1
"for_each(v.begin(), v.end(), _1 = bind(foo, _1));"
'for_each' is a non-mutating algorithm. 'transform' is better for this
case.
//-----------
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.
-Gary-
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk