【问题标题】:How to use std::for_each on a range of boost::function objects?如何在一系列 boost::function 对象上使用 std::for_each?
【发布时间】:2011-08-09 03:02:21
【问题描述】:
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? */ );

【问题讨论】:

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


    【解决方案1】:

    试试

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

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

    【讨论】:

      猜你喜欢
      • 2014-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-31
      • 1970-01-01
      • 2015-12-15
      相关资源
      最近更新 更多