为什么带有类型参数的运算符 () 可以应用于 result_of 上下文中的类型?

Why does operator () with type argument can be applied to type in the context of result_of?

本文关键字:of result 上下文 应用于 类型 类型参数 运算符 为什么      更新时间:2023-10-16

据我所知,result_of_t应该是一种类型,它将在表达式的计算结束时。decltype(&foo)下面的代码中产生了int (*)(int)类型,但是(int)decltype之外还有什么?

#include <type_traits>
int foo(int) {
return 0xdeadbeef;
}
int main()
{
using T = std::result_of_t<decltype(&foo)(int)>;
T t;
return 0;
}

但是(int(在decltype之外有什么?

它使我们感到困惑。std::result_of以"可爱"的方式定义。它是专门为F(Args...).其中F是函子类型,而Args...是提供给它的参数。

在您的情况下,调用的参数(int)

这以及定义的某些其他怪癖,这就是为什么std::result_of在 C++17 中被弃用并替换为std::invoke_result的原因。