如何在一系列boost :: function对象上使用std :: for_each?

时间:2011-08-09 03:02:21

标签: c++ boost boost-bind boost-function

class User    
{    
public:

    User(){}    
    virtual ~User(){}
    void Test( int in )    
    {    
    }    
}    

User user;

vector< boost::function< void() > > functions;

functions.push_back( boost::bind( &User::Test, &user, 2 ) );

functions.push_back( boost::bind( &User::Test, &user, 4 ) );

for_each( functions.begin(), functions.end() , /* What goes here? */ );

1 个答案:

答案 0 :(得分:3)

尝试

for_each( functions.begin(), functions.end(), mem_fn( &function< void() >::operator() ) );

其中mem_fnstd::tr1::mem_fnboost::mem_fn