Boost logo

Boost Users :

From: Joaquin M Lopez Munoz (joaquin_at_[hidden])
Date: 2008-07-17 09:54:50


Igor R <boost.lists <at> gmail.com> writes:

>
> Hi,
>
> std::vector<boost::function<void(void)> > functors;
> using namespace boost::lambda;
> std::for_each (functors.begin(), functor.end(), _1);
>
> The above compiles, but...does nothing. How can I enforce calling of
> operator () ?

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

bind here is boost::lambda::bind, in #include <boost/lambda/bind.hpp>,
not to be confused with boost::bind. On the other hand, you can
rewrite the stuff using Boost.Bind instead of Boost.Lambda:

  std::for_each(
    functors.begin(), functors.end(),
    boost::bind(&functor::operator(),::_1));

We are using here a different "bind" and a different "_1". This
name clash between both Boost libraries is a constant source
of grief.

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo


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