【发布时间】:2018-09-06 11:52:06
【问题描述】:
这里在 operator() 签名后使用 '-> decltype' 的语法是什么?它的用途是什么?
template<>
struct less<void>
{ // transparent functor for operator<
typedef int is_transparent;
template<class _Ty1,
class _Ty2>
constexpr auto operator()(_Ty1&& _Left, _Ty2&& _Right) const
-> decltype(static_cast<_Ty1&&>(_Left)
< static_cast<_Ty2&&>(_Right))
{ // transparently apply operator< to operands
return (static_cast<_Ty1&&>(_Left)
< static_cast<_Ty2&&>(_Right));
}
};
这是来自 C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\include\xstddef 第 276 行的代码。
为什么下面两行重复?
(static_cast<_Ty1&&>(_Left)
< static_cast<_Ty2&&>(_Right))
【问题讨论】:
-
stackoverflow.com/questions/22514855/… 第一个答案应该有帮助
-
是的,C++ 中总是有一些新东西 :)
标签: c++11