为什么带有类型参数的运算符 () 可以应用于 result_of 上下文中的类型?
Why does operator () with type argument can be applied to type in the context of result_of?
据我所知,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
的原因。
相关文章:
- Usages of std::move
- 使用 [] 运算符时"binding reference of type discards qualifiers"
- 如何处理 c++ 中类实现中的"invalid use of non-static data member"?
- 具有变量Number of Arguments的std::函数的矢量
- Capacity of a deque
- Deprecation of _writeBarrier()
- constexpr begin of a std::array
- 如何调整 std::vector of Eigen::MatrixXd 的大小
- C++ "error: invalid use of void expression"
- 我看到"use of undeclared identifier"错误,有人可以告诉我如何解决它吗?
- 赛通"Cannot take address of memoryview slice"
- C++ Version Of Double.longBitsToDouble
- 收到错误"invalid use of non-static data member 'stu::n' "
- C++ Usage of AsyncCallback
- 错误:"Left of getValue must have class/struct/union"
- Centos7 g++ "to_string is not in a member of std"
- 在C++中使用 Catch 测试框架编译错误"error: expected ';' at end of declaration list"
- 传递 std::vector of std::shared_ptr,而不是更新对象
- C++/SDL "initial value of reference to a non-const must be an lvalue"
- 摆脱编译器警告"warning: result of call is not used"