我有以下代码使用可变参数模板调用 std::async,
struct TestParent
{
template< typename Fn, typeName ...Args >
bool checkBlock( bool& toCheck,
Fn&& fn, Args&& ... args )
{
int startIndx = 0;
int endIndx = 10;
std::future< bool > tk( std::async( std::launch, fn, this,
startIndx, endIndx,
toCheck, args ... ) );
return tk.get();
}
}
struct TestChild: public TestParent
{
bool checkRules( const int, const int, bool& std::vector< bool >& );
bool check();
}
bool TestChild::checkRules( const int startIndx, const int endIndx,
bool& toCheck,
std::vector< bool >& results )
{
toCheck = true;
for ( int indx = startIndx; indx < endIndx; ++ indx )
{
bool checkedOk;
... do something checking.
results.push_back( checkedOk );
}
return true;
}
bool TestChild::check()
{
bool toCheck;
std::vector< bool > results;
return checkBlock( toCheck, &testChild::checkRules, this, &results);
}
但我收到以下编译错误消息:
没有匹配函数调用 'async(std::launch, bool (TestChild:: &)(int, int, bool&, std::vector&), TestParent , int&, int&, bool&, TestChild*&, std::vector *&)' startInx, endInx, nothingToCheck, args ... ) );
我认为这可能与我将附加参数与参数包一起传递的事实有关。任何人都知道这有什么问题,我应该怎么做才能让它发挥作用?