Difference between std::same_as and std::is_same

Viewed 413

I was reading through the documentation of std::same_as and it looks like it just forwards to std::is_same_v. cppreference has the following example implementation:

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 the && even necessary if std::is_same_v is commutative? And if std::same_as has identical semantics, what do I need it for? I can also use std::is_same_v as a constraint like this:

template <typename T>
void test(T x) requires std::is_same_v<T, int> {}
0 Answers
Related