Helper class that can be inherited from by a class to define the relational comparison operators in terms of a three_way_compare function provided by the Derived class, but preferentially implementing == and != to use operator==(Derived, Other) rather than three_way_compare.
More...
template<typename Derived>
class arene::base::generic_ordering_from_three_way_compare_and_equals< Derived >
Helper class that can be inherited from by a class to define the relational comparison operators in terms of a three_way_compare function provided by the Derived class, but preferentially implementing == and != to use operator==(Derived, Other) rather than three_way_compare.
Generates the <, >, <=, and >= comparison operators from a possibly overloaded static member function three_way_compare in the Derived class that accepts a const Derived& as the first argument and any other type as the second argument, and returns a strong_ordering value indicating whether the first is less than, equal to or greater than the second. These three_way_compare functions must not throw exceptions.
Even if the derived class provides a fast_inequality_check function, it is not used, because the exact operator== is preferred over three_way_compare.
- Template Parameters
-
| Derived | The type of the derived class. The comparison operators provided take parameters of this type. |
For example:
class string_like : arene::base::generic_ordering_from_three_way_compare_and_equals<string_like> {
public:
three_way_compare(string_like const& lhs, string_like const& rhs) noexcept {
return real_comparison(lhs, rhs);
}
three_way_compare(string_like const& lhs, arene::base::string_view rhs) noexcept {
return real_comparison(lhs, rhs);
}
three_way_compare(string_like const& lhs, arene::base::null_terminated_string_view rhs) noexcept {
return real_comparison(lhs, rhs);
}
ARENE_NODISCARD friend bool operator==(string_like
const& lhs, arene::base::string_view rhs)
noexcept {
return to_string_view(lhs) == rhs;
}
ARENE_NODISCARD friend bool operator==(string_like
const& lhs, string_like
const& rhs)
noexcept {
return lhs == to_string_view(rhs);
}
};
Here, MyClass has comparison operators for comparing instances of MyClass with each other, or with OtherClass, or with YetAnotherClass. Equality comparisons with OtherClass will use operator==, while comparisons with YetAnotherClass will use three_way_compare.