For example, the compare of std::less is defined as a template struct
template< class T = void >
struct less;
While std::compare_three_way is defined just as a normal struct, and its operator() is a template function. (code from MSVC)
struct compare_three_way {
template <class _Ty1, class _Ty2>
requires three_way_comparable_with<_Ty1, _Ty2> // TRANSITION, GH-489
constexpr auto operator()(_Ty1&& _Left, _Ty2&& _Right) const
noexcept(noexcept(_STD forward<_Ty1>(_Left) <=> _STD forward<_Ty2>(_Right))) /* strengthened */ {
return _STD forward<_Ty1>(_Left) <=> _STD forward<_Ty2>(_Right);
}
using is_transparent = int;
};
So why isn't std::compare_three_way a template struct?
template <class _Ty1, class _Ty2>
requires three_way_comparable_with<_Ty1, _Ty2>
struct compare_three_way {
constexpr auto operator()(_Ty1&& _Left, _Ty2&& _Right) const;
};
By the way, could I replace std::less<T> by std::three_way_compare in my own implementation of containers, like Comparer<T> in C#.