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, and an optional fast-inequality check heuristic.
More...
|
| template<typename Self, typename Other, constraints< std::enable_if_t< std::is_same< Self, Derived >::value >, std::enable_if_t< is_three_way_comparable_v< Derived, Other > >, std::enable_if_t<!is_three_way_comparable_v< Other, Derived > > > = nullptr> |
| ARENE_NODISCARD friend constexpr auto | operator!= (Other const &lhs, Self const &rhs) noexcept -> bool |
| | Inequality comparison operator for instances of Derived with Other.
|
| |
| template<typename Self, typename Other, constraints< std::enable_if_t< std::is_same< Self, Derived >::value >, std::enable_if_t< is_three_way_comparable_v< Derived, Other > > > = nullptr> |
| ARENE_NODISCARD friend constexpr auto | operator!= (Self const &lhs, Other const &rhs) noexcept -> bool |
| | Inequality comparison operator for instances of Derived with Other.
|
| |
| template<typename Self, typename Other, constraints< std::enable_if_t< std::is_same< Self, Derived >::value >, std::enable_if_t< is_three_way_comparable_v< Derived, Other > >, std::enable_if_t<!is_three_way_comparable_v< Other, Derived > > > = nullptr> |
| ARENE_NODISCARD friend constexpr auto | operator< (Other const &lhs, Self const &rhs) noexcept -> bool |
| | Less-than comparison operator for instances of Derived with Other.
|
| |
| template<typename Self, typename Other, constraints< std::enable_if_t< std::is_same< Self, Derived >::value >, std::enable_if_t< is_three_way_comparable_v< Derived, Other > > > = nullptr> |
| ARENE_NODISCARD friend constexpr auto | operator< (Self const &lhs, Other const &rhs) noexcept -> bool |
| | Less-than comparison operator for instances of Derived with Other.
|
| |
| template<typename Self, typename Other, constraints< std::enable_if_t< std::is_same< Self, Derived >::value >, std::enable_if_t< is_three_way_comparable_v< Derived, Other > >, std::enable_if_t<!is_three_way_comparable_v< Other, Derived > > > = nullptr> |
| ARENE_NODISCARD friend constexpr auto | operator<= (Other const &lhs, Self const &rhs) noexcept -> bool |
| | Less-than-or-equal comparison operator for instances of Derived with Other.
|
| |
| template<typename Self, typename Other, constraints< std::enable_if_t< std::is_same< Self, Derived >::value >, std::enable_if_t< is_three_way_comparable_v< Derived, Other > > > = nullptr> |
| ARENE_NODISCARD friend constexpr auto | operator<= (Self const &lhs, Other const &rhs) noexcept -> bool |
| | Less-than-or-equal comparison operator for instances of Derived with Other.
|
| |
| template<typename Self, typename Other, constraints< std::enable_if_t< std::is_same< Self, Derived >::value >, std::enable_if_t< is_three_way_comparable_v< Derived, Other > >, std::enable_if_t<!is_three_way_comparable_v< Other, Derived > > > = nullptr> |
| ARENE_NODISCARD friend constexpr auto | operator== (Other const &lhs, Self const &rhs) noexcept -> bool |
| | Equality comparison operator for instances of Derived with Other.
|
| |
| template<typename Self, typename Other, constraints< std::enable_if_t< std::is_same< Self, Derived >::value >, std::enable_if_t< is_three_way_comparable_v< Derived, Other > >, std::enable_if_t<!has_fast_inequality_check_v< Derived, Other > > > = nullptr> |
| ARENE_NODISCARD friend constexpr auto | operator== (Self const &lhs, Other const &rhs) noexcept -> bool |
| | Equality comparison operator for instances of Derived with Other.
|
| |
| template<typename Self, typename Other, constraints< std::enable_if_t< std::is_same< Self, Derived >::value >, std::enable_if_t< is_three_way_comparable_v< Derived, Other > >, std::enable_if_t< has_fast_inequality_check_v< Derived, Other > > > = nullptr> |
| ARENE_NODISCARD friend constexpr auto | operator== (Self const &lhs, Other const &rhs) noexcept -> bool |
| | Equality comparison operator for instances of Derived with Other.
|
| |
| template<typename Self, typename Other, constraints< std::enable_if_t< std::is_same< Self, Derived >::value >, std::enable_if_t< is_three_way_comparable_v< Derived, Other > >, std::enable_if_t<!is_three_way_comparable_v< Other, Derived > > > = nullptr> |
| ARENE_NODISCARD friend constexpr auto | operator> (Other const &lhs, Self const &rhs) noexcept -> bool |
| | Greater-than comparison operator for instances of Derived with Other.
|
| |
| template<typename Self, typename Other, constraints< std::enable_if_t< std::is_same< Self, Derived >::value >, std::enable_if_t< is_three_way_comparable_v< Derived, Other > > > = nullptr> |
| ARENE_NODISCARD friend constexpr auto | operator> (Self const &lhs, Other const &rhs) noexcept -> bool |
| | Greater-than comparison operator for instances of Derived with Other.
|
| |
| template<typename Self, typename Other, constraints< std::enable_if_t< std::is_same< Self, Derived >::value >, std::enable_if_t< is_three_way_comparable_v< Derived, Other > >, std::enable_if_t<!is_three_way_comparable_v< Other, Derived > > > = nullptr> |
| ARENE_NODISCARD friend constexpr auto | operator>= (Other const &lhs, Self const &rhs) noexcept -> bool |
| | Greater-than-or-equal comparison operator for instances of Derived with Other.
|
| |
| template<typename Self, typename Other, constraints< std::enable_if_t< std::is_same< Self, Derived >::value >, std::enable_if_t< is_three_way_comparable_v< Derived, Other > > > = nullptr> |
| ARENE_NODISCARD friend constexpr auto | operator>= (Self const &lhs, Other const &rhs) noexcept -> bool |
| | Greater-than-or-equal comparison operator for instances of Derived with Other.
|
| |
template<typename Derived>
class arene::base::generic_ordering_from_three_way_compare< 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, and an optional fast-inequality check heuristic.
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.
The derived class can optionally provide a static member function fast_inequality_check that accepts a const Derived& as the first argument and any other type as the second argument, and returns a inequality_heuristic value indicating whether the first is definitely not equal to the second, or may or may not be equal to the second. These fast_inequality_check functions must not throw exceptions. The generated operator== and operator!= overloads will invoke fast_inequality_check prior to three_way_compare if there is an overload provided that accepts the given types.
- 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<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);
}
fast_inequality_check(string_like const& lhs, string_like const& rhs) noexcept {
}
fast_inequality_check(string_like const& lhs, arene::base::string_view rhs) noexcept {
}
};
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 fast_inequality_check to avoid calling a potentially expensive three_way_compare for instances that are definitely not equal. e.g. this may be used to check the size of a container, and avoid doing elementwise comparisons when ordering is not required.