boost::bind作为参数接受带有n个参数的函数,并在以后的函数调用中使用相同的参数
我可以做下面这样的事情吗?是否可能,或者是否有任何解决办法boost::bind作为参数接受带有n个参数的函数,并在以后的函数调用中使用相同的参数,boost,boost-bind,Boost,Boost Bind,我可以做下面这样的事情吗?是否可能,或者是否有任何解决办法 .. PostWorkToThread( boost::bind(func_x, arg1) ); PostWorkToThread( boost::bind(func_y, arg1, arg2) ); PostWorkToThread( boost::bind(func_z, arg1, arg2, arg3) ); .. void PostWorkToThread( boost::bind xxx ) { PostWo
..
PostWorkToThread( boost::bind(func_x, arg1) );
PostWorkToThread( boost::bind(func_y, arg1, arg2) );
PostWorkToThread( boost::bind(func_z, arg1, arg2, arg3) );
..
void PostWorkToThread( boost::bind xxx )
{
PostWork( boost::bind(xxx) ); or
PostWork( xxx );
}
谢谢,非常感谢您的建议。由于未指定由(和)生成的函数对象的类型,您应该将
PostWorkToThread
作为模板:
template< typename Fun >
void PostWorkToThread( Fun xxx )
{
// Enqueue xxx for execution
}
注意,在这种情况下,
boost::function
(和std::function
)可能必须动态分配内存来存储函数对象。但是,您可能无论如何都必须将函数排队执行,因此这可能不是问题。由于未指定由(和)生成的函数对象的类型,您应该将PostWorkToThread
设置为模板:
template< typename Fun >
void PostWorkToThread( Fun xxx )
{
// Enqueue xxx for execution
}
注意,在这种情况下,boost::function
(和std::function
)可能必须动态分配内存来存储函数对象。但是,您可能无论如何都必须这样做才能将函数排队执行,因此这可能不是问题