Boost logo

Boost Users :

Subject: [Boost-users] [Bind] Finding the right syntax.
From: Robert Jones (robertgbjones_at_[hidden])
Date: 2011-10-17 06:03:10


Hi All

In the code below my objective is pass a nullary function object to apply,
and for that
nullary function object to be 'my_function()' called with each member of the
vector. How can I
recode the call to apply as a unary bind expression such that I can write
the for loop
as a for_each loop?

Thx,

- Rob.

#include <vector>
#include "boost/function.hpp"
#include "boost/bind.hpp"

void apply( boost::function<void()> f )
{
    f( );
}

int main( )
{
    static boost::function<void(int)> my_function = 0;

    std::vector<int> v;

    for ( std::vector<int>::iterator i = v.begin( ); i != v.end( ); ++ i )
    {
        apply( bind( my_function, * i ) );
    }
}



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