std::is_invocable<std::decay_t<void(int&)>, std::decay_t<int>>::value
评估为假。
但是
void(int&)
衰减到void*(int&)
和int
至int
而且我可以这样使用std::invoke
:
void f(int&);
...
auto* fp = f;
int i = 0;
std::invoke(fp, i);
[当我看std::thread
构造函数时碰到了这个问题:
template<typename _Callable, typename... _Args,
typename = _Require<__not_same<_Callable>>>
explicit
thread(_Callable&& __f, _Args&&... __args)
{
static_assert( __is_invocable<typename decay<_Callable>::type,
typename decay<_Args>::type...>::value,
"std::thread arguments must be invocable after conversion to rvalues"
);
我理解为什么不鼓励传递对std::thread
的构造函数的引用(我们仍然可以使用std::ref()
,但我不明白为什么不能用void *(int&)
调用int
。
std::is_invocable<..., int>
尝试使用int
rvalue