Boost logo

Boost Users :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2005-09-23 11:14:52


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.)


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net