-1

What is the syntax used here with '-> decltype' after the operator() signature and what is it for?

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));
    }
};

this is the code from C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\include\xstddef line 276.

Why are the following two lines duplicated?

(static_cast<_Ty1&&>(_Left)
        < static_cast<_Ty2&&>(_Right))
Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
Alexey Starinsky
  • 3,699
  • 3
  • 21
  • 57

1 Answers1

0

->decltype(static_cast<_Ty1&&>(_Left) returns the type of static_cast<_Ty1&&>(_Left) and declare it as the return type of the function.

E.G.

auto function(int x ) -> int and int function(int x ) are the same

Simo
  • 955
  • 8
  • 18