23 Sep
2005
23 Sep
'05
4:14 p.m.
Seb Martel wrote:
std::transform( x.begin(), x.end(), std::back_inserter(y), boost::bind( &foo, _1 ) );
Or even
std::transform( x.begin(), x.end(), std::back_inserter(y), foo );
Could it be possible that bind detects identity usage like this and notify of the inefficiency?
bind( foo, _1 ) is not identity. It converts foo into a function object that is capable of taking N arguments, N >= 1, and ignoring all but the first. (Similarly, bind( foo, _2 ) ignores all arguments but the second.) In a template parameterized by the type of f, bind( f, _1 ) also works as an "universal adaptor" of sorts, turning member pointers and reference_wrappers into function objects (and defining a ::result_type as an extra bonus.)