-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
  • 413,367
  • 61
  • 711
  • 904
Alexey Starinsky
  • 3,022
  • 2
  • 14
  • 49

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
  • 945
  • 8
  • 18