Код: Выделить всё
#include
struct A {};
struct B {};
constexpr bool operator==(A, A) {
return true;
}
constexpr bool operator==(B, B) {
return true;
}
constexpr bool operator==(A, B) {
return true;
}
template
concept IsEqualityComparable = requires(T a, U b) {
{ a == b } -> std::same_as;
{ b == a } -> std::same_as;
};
static_assert(IsEqualityComparable); // true as expected!
static_assert(IsEqualityComparable); // true as expected!
static_assert(IsEqualityComparable); // true as expected!
static_assert(IsEqualityComparable); // true as expected!
static_assert(std::equality_comparable_with); // true as expected!
static_assert(std::equality_comparable_with); // true as expected!
static_assert(std::equality_comparable_with); // !!!false!!! why???
static_assert(std::equality_comparable_with); // !!!false!!! why???
Зачем ему нужен общий тип для сравнения двух не связанных с ними типов, даже если соответствующий оператор == был хорошо определен?
Подробнее здесь: https://stackoverflow.com/questions/796 ... plest-case