Boost logo

Boost Users :

From: Eric MALENFANT (Eric.Malenfant_at_[hidden])
Date: 2008-07-17 10:30:06


Igor R [boost.lists_at_[hidden]], le 17 juillet 2008 10:09:
>> typedef boost::function<void(void)> functor;
>> std::vector<functor> functors;
>> ...
>> using namespace boost::lambda;
>> std::for_each(
>> functors.begin(), functors.end(),
>> bind(&functor::operator(),_1));
>
> Oh, I see... So the explicit bind is unavoidable :(.

As shown here: http://www.boost.org/doc/libs/1_35_0/doc/html/lambda/le_in_details.html#lambda.function_pointers_as_targets, the bind() is unavoidable, but it does not have to be that explicit. This should work:

  std::for_each(functors.begin(), functors.end(), bind(_1));

Note that Lambda may be unable to deduce the return type for some functors. See http://www.boost.org/doc/libs/1_35_0/doc/html/lambda/le_in_details.html#lambda.function_objects_as_targets for more information.

Éric Malenfant
---------------------------------------------
Sometimes I think the surest sign that intelligent life exists
elsewhere in the universe is that none of it has tried to contact us.
- Calvin


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