【问题标题】:What does '->' mean after a function declaration in C++ 11? [duplicate]在 C++ 11 中的函数声明之后,'->' 是什么意思? [复制]
【发布时间】: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))

【问题讨论】:

标签: c++11


【解决方案1】:

-&gt;decltype(static_cast&lt;_Ty1&amp;&amp;&gt;(_Left)返回static_cast&lt;_Ty1&amp;&amp;&gt;(_Left)的类型,并声明为函数的返回类型。

E.G.

auto function(int x ) -&gt; intint function(int x ) 是一样的

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-21
    • 1970-01-01
    • 2011-04-08
    • 2018-03-02
    • 2011-03-09
    相关资源
    最近更新 更多