2

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> {}
Jan Schultke
  • 17,446
  • 6
  • 47
  • 96
  • The question is answered: https://stackoverflow.com/questions/58509147/why-does-same-as-concept-check-type-equality-twice If you want to understand more about concepts, check this blog: https://akrzemi1.wordpress.com/2020/05/07/ordering-by-constraints/ – NN_ Jan 14 '22 at 08:10

0 Answers0