6

cppref gives a possible implementation of std::same_as:

namespace detail {
    template<class T, class U>
    concept SameHelper = std::is_same_v<T, U>;
}

template<class T, class U>
concept same_as = detail::SameHelper<T, U> && detail::SameHelper<U, T>;

Why is it not implemented just as follows:

template<class T, class U>
concept same_as = std::is_same_v<T, U> && std::is_same_v<U, T>;

or even shorter:

template<class T, class U>
concept same_as = std::is_same_v<T, U>;
xmllmx
  • 39,765
  • 26
  • 162
  • 323

1 Answers1

2

It is t handle subsumption which only happens with concepts.

With your proposal,

same_as<T, U> doesn't subsume same_as<U, T>.

Further reading in cppreference.

Jarod42
  • 203,559
  • 14
  • 181
  • 302