![](/img/trans.png)
[英]Xplot for jupyter: “no template named decay_t in namespace std”
[英]Why std::is_invocable<std::decay_t<void(int&)>, std::decay_t<int>>::value is false?
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
右值作為參數。 它相當於std::is_invocable<..., int &&>
。
使用std::is_invocable<..., int &>
。
...正式確定
INVOKE(declval<Fn>(), declval<ArgTypes>()...)
是否格式正確...
即使我們忽略INVOKE
是什么,您也可以看到is_invocable
是使用std::declval<ArgType>()
定義的,它返回ArgType &&
。
ArgType &&
是一個右值引用。 除非ArgType
是左值引用,在這種情況下ArgType &&
等效於ArgType
並且是左值引用(根據引用折疊規則)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.