为什么std :: is_invocable ,std :: decay_t > :: value为false?

问题描述 投票:1回答:1
std::is_invocable<std::decay_t<void(int&)>, std::decay_t<int>>::value

评估为假。

但是

void(int&)衰减到void*(int&)

intint

而且我可以这样使用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

c++ c++11 stdthread
1个回答
0
投票
std::is_invocable<..., int>尝试使用int

rvalue

© www.soinside.com 2019 - 2024. All rights reserved.