Следующий код не компилируется:
template< typename Fn1, typename Fn2 >
bool templateFunctionOne( Fn1&& fn1, Fn2&& fn2 )
{
int v = 5;
fn1( v );
return fn2( v );
}
template < typename Fn1, typename Fn2 >
bool templateFunctionTwo( Fn1&& fn1, Fn2&& fn2 )
{
std::future< bool > tk( std::async( std::launch::async,
&templateFunctionOne< typename std::remove_reference<Fn1>::type,
typename std::remove_reference<Fn2>::type >,
std::forward<Fn1>(fn1),
std::forward<Fn2>(fn2) ) );
return tk.get();
}
bool printThis( int value )
{
cout << "this value = "
<< value
<< endl;
return true;
}
bool printThat( int value )
{
cout << "that value = "
<< value
<< endl;
return true;
}
int main()
{
auto func1 = std::bind( &printThis, std::placeholders::_1 );
auto func2 = std::bind( &printThat, std::placeholders::_2 );
return templateFunctionTwo( func1, func2 );
}
Я получаю такие ошибки:
error: no match for call to '(std::_Bind<boo (*(std::_Placeholder<2>))(int)>) (int&)'
return fn2( thatValue );
~~~^~~~~~~~~~~~~
template argument deduction/substitution failed:
candidate: template<class ... _Args, class _Result> _Result std::_Bind<_Functor(_Bound_args ...)>::operator()(_Args&& ...) const [with _Args = {_Args ...}; _Result = _Result; _Functor = bool (*)(int); _Bound_args = {std::_Placeholder<2>}]
operator()(_Args&&... --args) cont
^~~~~~~~
Я знаю, что это как-то связано с передачей нескольких указателей на функциишаблон, но просто не знаю, где и что.Может ли кто-нибудь помочь указать, где мои ошибки, пожалуйста?