Why is std::same_as implemented in such a weird way?

1.1k Views Asked by At

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>;
1

There are 1 best solutions below

3
Jarod42 On BEST ANSWER

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.