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

标签 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? */ );

最佳答案

尝试

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

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

关于c++ - 如何在一系列 boost::function 对象上使用 std::for_each ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6990955/

相关文章:

c++ - QOpenGLWidget 和 QPainter ,不能同时渲染 2D 和 3D

c++ - 是否有用于 Visual C++ 或其他 IDE 的工具,允许超过 1 个程序员(在线)同时处理同一个项目?

c++ - 在 for 循环和变量值中,此代码出现多个错误;

c++ - 使用 CUDA 编译 main.cpp 文件

c++ - 可以将多个 boost::signal 连接到 1 个插槽吗?

c++ - boost::mutex 在模板中使用时不起作用

c++ - 向现有多索引容器添加更多索引

objective-c - 我可以将 boost::bind() 转换为 Objective C 函数吗?

c++ - 从结构数组中提取结构成员

c++ - boost绑定(bind)类函数指针