开发者

How to use std::for_each on a range of boost::function objects?

开发者 https://www.devze.com 2023-03-26 15:42 出处:网络
class User { public: User(){} virtual ~User(){} void Test( int in ) { } } User user; vector< b开发者_C百科oost::function< void() > > functions;
class User    
{    
public:

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

User user;

vector< b开发者_C百科oost::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? */ );


Try

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

Where mem_fn is either std::tr1::mem_fn or boost::mem_fn.

0

精彩评论

暂无评论...
验证码 换一张
取 消