Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
arene::base::generic_ordering_from_three_way_compare_and_equals< Derived > Class Template Reference

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...

Inheritance diagram for arene::base::generic_ordering_from_three_way_compare_and_equals< Derived >:
Inheritance graph

Protected Member Functions

constexpr generic_ordering_from_three_way_compare_and_equals () noexcept=default
 Default constructor is protected.
 
constexpr generic_ordering_from_three_way_compare_and_equals (generic_ordering_from_three_way_compare_and_equals &&other) noexcept=default
 Default move constructor is protected.
 
constexpr generic_ordering_from_three_way_compare_and_equals (generic_ordering_from_three_way_compare_and_equals const &other) noexcept=default
 Default copy constructor is protected.
 
 ~generic_ordering_from_three_way_compare_and_equals () noexcept=default
 Default destructor is protected.
 
constexpr auto operator= (generic_ordering_from_three_way_compare_and_equals &&other) &noexcept -> generic_ordering_from_three_way_compare_and_equals &=default
 Default move assignment is protected.
 
constexpr auto operator= (generic_ordering_from_three_way_compare_and_equals const &other) &noexcept -> generic_ordering_from_three_way_compare_and_equals &=default
 Default copy assignment is protected.
 

Friends

template<typename Self, typename Other, constraints< std::enable_if_t< std::is_same< Self, Derived >::value >, std::enable_if_t< operators_detail::eligible_for_reversed_equals_with_v< Self, Other > > > = 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_equality_comparable_v< Self, 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< operators_detail::eligible_for_reversed_equals_with_v< Self, Other > > > = 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<!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.
 

Detailed Description

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
DerivedThe type of the derived class. The comparison operators provided take parameters of this type.

For example:

/// @brief An example string-like class with generated comparison operations
class string_like : arene::base::generic_ordering_from_three_way_compare_and_equals<string_like> {
public:
/// @brief a three-way ordering function for two @c string_like instances
/// @param lhs The first object being compared
/// @param rhs The second object being compared
/// @return arene::base::strong_ordering holding the result of the comparison
three_way_compare(string_like const& lhs, string_like const& rhs) noexcept {
return real_comparison(lhs, rhs);
}
/// @brief a three-way ordering function for a @c string_like object with a @c arene::base::string_view object
/// @param lhs The first object being compared
/// @param rhs The second object being compared
/// @return arene::base::strong_ordering holding the result of the comparison
three_way_compare(string_like const& lhs, arene::base::string_view rhs) noexcept {
return real_comparison(lhs, rhs);
}
/// @brief a three-way ordering function for a @c string_like object with a @c
/// arene::base::null_terminated_string_view object
/// @param lhs The first object being compared
/// @param rhs The second object being compared
/// @return arene::base::strong_ordering holding the result of the comparison
three_way_compare(string_like const& lhs, arene::base::null_terminated_string_view rhs) noexcept {
return real_comparison(lhs, rhs);
}
/// @brief A fast inequality check for two @c string_like types to avoid character-by-character comparisons if they
/// have different lengths
/// @param lhs The first object being compared
/// @param rhs The second object being compared
/// @return arene::base::inequality_heuristic which is @c arene::base::inequality_heuristic::definitely_not_equal if
/// the strings have different lengths and @c arene::base::inequality_heuristic::may_be_equal_or_not_equal otherwise
ARENE_NODISCARD friend bool operator==(string_like const& lhs, arene::base::string_view rhs) noexcept {
return to_string_view(lhs) == rhs;
}
/// @brief A fast inequality check for two @c string_like types to avoid character-by-character comparisons if they
/// @param lhs The first object being compared
/// @param rhs The second object being compared
/// @return arene::base::inequality_heuristic which is @c arene::base::inequality_heuristic::definitely_not_equal if
/// the strings have different lengths and @c arene::base::inequality_heuristic::may_be_equal_or_not_equal otherwise
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.

Constructor & Destructor Documentation

◆ generic_ordering_from_three_way_compare_and_equals() [1/3]

template<typename Derived>
arene::base::generic_ordering_from_three_way_compare_and_equals< Derived >::generic_ordering_from_three_way_compare_and_equals ( )
constexprprotecteddefaultnoexcept

Default constructor is protected.

◆ ~generic_ordering_from_three_way_compare_and_equals()

Default destructor is protected.

◆ generic_ordering_from_three_way_compare_and_equals() [2/3]

template<typename Derived>
arene::base::generic_ordering_from_three_way_compare_and_equals< Derived >::generic_ordering_from_three_way_compare_and_equals ( generic_ordering_from_three_way_compare_and_equals< Derived > const & other)
constexprprotecteddefaultnoexcept

Default copy constructor is protected.

Parameters
otherThe source object

◆ generic_ordering_from_three_way_compare_and_equals() [3/3]

template<typename Derived>
arene::base::generic_ordering_from_three_way_compare_and_equals< Derived >::generic_ordering_from_three_way_compare_and_equals ( generic_ordering_from_three_way_compare_and_equals< Derived > && other)
constexprprotecteddefaultnoexcept

Default move constructor is protected.

Parameters
otherThe source object

Member Function Documentation

◆ operator=() [1/2]

template<typename Derived>
auto arene::base::generic_ordering_from_three_way_compare_and_equals< Derived >::operator= ( generic_ordering_from_three_way_compare_and_equals< Derived > && other) & -> generic_ordering_from_three_way_compare_and_equals &=default
constexprprotecteddefaultnoexcept

Default move assignment is protected.

Parameters
otherThe source object

◆ operator=() [2/2]

template<typename Derived>
auto arene::base::generic_ordering_from_three_way_compare_and_equals< Derived >::operator= ( generic_ordering_from_three_way_compare_and_equals< Derived > const & other) & -> generic_ordering_from_three_way_compare_and_equals &=default
constexprprotecteddefaultnoexcept

Default copy assignment is protected.

Parameters
otherThe source object

Friends And Related Symbol Documentation

◆ operator!= [1/2]

template<typename Derived>
template<typename Self, typename Other, constraints< std::enable_if_t< std::is_same< Self, Derived >::value >, std::enable_if_t< operators_detail::eligible_for_reversed_equals_with_v< Self, Other > > > = nullptr>
ARENE_NODISCARD friend constexpr auto operator!= ( Other const & lhs,
Self const & rhs ) -> bool
friend

Inequality comparison operator for instances of Derived with Other.

Template Parameters
Selfthe type of the Derived object to compare, used for constraints
Otherthe type of the object to compare to
Parameters
lhsThe instance of Derived to compare
rhsThe instance of Other to compare
Returns
bool true if lhs is not equal to rhs, false otherwise

◆ operator!= [2/2]

template<typename Derived>
template<typename Self, typename Other, constraints< std::enable_if_t< std::is_same< Self, Derived >::value >, std::enable_if_t< is_equality_comparable_v< Self, Other > > > = nullptr>
ARENE_NODISCARD friend constexpr auto operator!= ( Self const & lhs,
Other const & rhs ) -> bool
friend

Inequality comparison operator for instances of Derived with Other.

Template Parameters
Selfthe type of the Derived object to compare, used for constraints
Otherthe type of the object to compare to
Parameters
lhsThe instance of Derived to compare
rhsThe instance of Other to compare
Returns
bool true if lhs is not equal to rhs, false otherwise

◆ operator< [1/2]

template<typename Derived>
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 ) -> bool
friend

Less-than comparison operator for instances of Derived with Other.

Template Parameters
Selfthe type of the Derived object to compare, used for constraints
OtherThe type of the object to compare to
Parameters
lhsThe instance of Other to compare
rhsThe instance of Derived to compare
Returns
bool true if lhs is less than rhs, false otherwise

◆ operator< [2/2]

template<typename Derived>
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 ) -> bool
friend

Less-than comparison operator for instances of Derived with Other.

Template Parameters
Selfthe type of the Derived object to compare, used for constraints
Otherthe type of the object to compare to
Parameters
lhsThe instance of Derived to compare
rhsThe instance of Other to compare
Returns
bool true if lhs is less than rhs, false otherwise

◆ operator<= [1/2]

template<typename Derived>
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 ) -> bool
friend

Less-than-or-equal comparison operator for instances of Derived with Other.

Template Parameters
Selfthe type of the Derived object to compare, used for constraints
Otherthe type of the object to compare to
Parameters
lhsThe instance of Other to compare
rhsThe instance of Derived to compare
Returns
bool true if lhs is less than or equal to rhs, false otherwise

◆ operator<= [2/2]

template<typename Derived>
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 ) -> bool
friend

Less-than-or-equal comparison operator for instances of Derived with Other.

Template Parameters
Selfthe type of the Derived object to compare, used for constraints
Otherthe type of the object to compare to
Parameters
lhsThe instance of Derived to compare
rhsThe instance of Other to compare
Returns
bool true if lhs is less than or equal to rhs, false otherwise

◆ operator==

template<typename Derived>
template<typename Self, typename Other, constraints< std::enable_if_t< std::is_same< Self, Derived >::value >, std::enable_if_t< operators_detail::eligible_for_reversed_equals_with_v< Self, Other > > > = nullptr>
ARENE_NODISCARD friend constexpr auto operator== ( Other const & lhs,
Self const & rhs ) -> bool
friend

Equality comparison operator for instances of Derived with Other.

Template Parameters
Selfthe type of the Derived object to compare, used for constraints
Otherthe type of the object to compare to
Parameters
lhsThe instance of Derived to compare
rhsThe instance of Other to compare
Returns
bool true if lhs is equal to rhs, false otherwise

◆ operator> [1/2]

template<typename Derived>
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 ) -> bool
friend

Greater-than comparison operator for instances of Derived with Other.

Template Parameters
Selfthe type of the Derived object to compare, used for constraints
Otherthe type of the object to compare to
Parameters
lhsThe instance of Other to compare
rhsThe instance of Derived to compare
Returns
bool true if lhs is greater than rhs, false otherwise

◆ operator> [2/2]

template<typename Derived>
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 ) -> bool
friend

Greater-than comparison operator for instances of Derived with Other.

Template Parameters
Selfthe type of the Derived object to compare, used for constraints
Otherthe type of the object to compare to
Parameters
lhsThe instance of Derived to compare
rhsThe instance of Other to compare
Returns
bool true if lhs is greater than rhs, false otherwise

◆ operator>= [1/2]

template<typename Derived>
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 ) -> bool
friend

Greater-than-or-equal comparison operator for instances of Derived with Other.

Template Parameters
Selfthe type of the Derived object to compare, used for constraints
Otherthe type of the object to compare to
Parameters
lhsThe instance of Other to compare
rhsThe instance of Derived to compare
Returns
bool true if lhs is greater than or equal to rhs, false otherwise

◆ operator>= [2/2]

template<typename Derived>
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 ) -> bool
friend

Greater-than-or-equal comparison operator for instances of Derived with Other.

Template Parameters
Selfthe type of the Derived object to compare, used for constraints
Otherthe type of the object to compare to
Parameters
lhsThe instance of Derived to compare
rhsThe instance of Other to compare
Returns
bool true if lhs is greater than or equal to rhs, false otherwise

The documentation for this class was generated from the following file: