我正在尝试使用std::bind
将this
绑定到在QtConcurrent::blockingMapped
中使用的方法。
头文件:
class TuringMachine
{
private:
TRTable table;
std::set<ConfigNode*> currentConfigs;
//function object
std::function<std::set<ConfigNode*>( const TuringMachine*, ConfigNode*)> step_f;
//method it will hold
std::set<ConfigNode *> step(TuringMachine* this_m ,ConfigNode *parent);
std::set<ConfigNode*>& makeStep();
}
Source:
TuringMachine::TuringMachine(/**/)
{
step_f = std::bind(&TuringMachine::step, this, std::placeholders::_1);
}
std::set<ConfigNode*> &TuringMachine::makeStep(){
auto configSet = QtConcurrent::blockingMapped<QLinkedList<std::set<ConfigNode*>>>(currentConfigs, step_f);//concurrent execution!
/**/
return currentConfigs;
}
std::set<ConfigNode*> TuringMachine::step(TuringMachine *this_m, ConfigNode * parent){ //the actual step
/**/
}
我所做的是并行运行步骤,与currentConfigs
中的每个ConfigNode
上的blockingMapped
同时运行。我使用std::bind
将this
绑定到step
,使其只需要一个参数,就像blockingMapped
的文档中所述。
我得到的结果是:
error: no match for call to '(std::_Bind<std::_Mem_fn<std::set<ConfigNode*> (TuringMachine::*)(TuringMachine*, ConfigNode*)>(TuringMachine*, std::_Placeholder<1>)>) (const TuringMachine*, ConfigNode*)'
.../Qt/474/gcc/include/QtCore/qtconcurrentmapkernel.h:121: error: no match for call to '(std::function<std::set<ConfigNode*>(const TuringMachine*, ConfigNode*)>) (ConfigNode* const&)'
.../Qt/474/gcc/include/QtCore/qtconcurrentmapkernel.h:136: error: no match for call to '(std::function<std::set<ConfigNode*>(const TuringMachine*, ConfigNode*)>) (ConfigNode* const&)'
并且 注意:需要2个参数,但只提供了1个
我哪里错了?
编辑
已纠正,可工作版本(供将来“参考”):
头部:
//function object
std::function<std::set<ConfigNode*>( ConfigNode*)> step_f;
//method it will hold
std::set<ConfigNode *> step(ConfigNode *parent);
来源:
TuringMachine::TuringMachine(/**/)
{
step_f = std::bind(&TuringMachine::step, this, std::placeholders::_1);
}
this
? - TeaOverflowstd::bind(&foo::bar, bar())
。 - Stephan DollbergConfigNode
对象上并发运行step
。blockingMapped
似乎是个好主意,因为它就是这样做的。但是我不能只使用成员函数,如此处所示。我必须将其绑定或使其成为静态/全局函数。 - TeaOverflowstep_f = bind(&TuringMachine::step, this, placeholders::_1);
,它可以工作了。谢谢 - TeaOverflow