Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
arene::base::generic_ordering_from_three_way_compare< 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, and an optional fast-inequality check heuristic. More...

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

Protected Member Functions

constexpr generic_ordering_from_three_way_compare () noexcept=default
 Default constructor is protected.
 
constexpr generic_ordering_from_three_way_compare (generic_ordering_from_three_way_compare &&other) noexcept=default
 Default move constructor is protected.
 
constexpr generic_ordering_from_three_way_compare (generic_ordering_from_three_way_compare const &other) noexcept=default
 Default copy constructor is protected.
 
 ~generic_ordering_from_three_way_compare () noexcept=default
 Default destructor is protected.
 
constexpr auto operator= (generic_ordering_from_three_way_compare &&other) &noexcept -> generic_ordering_from_three_way_compare &=default
 Default move assignment is protected.
 
constexpr auto operator= (generic_ordering_from_three_way_compare const &other) &noexcept -> generic_ordering_from_three_way_compare &=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< 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.
 

Detailed Description

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
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<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
fast_inequality_check(string_like const& lhs, string_like const& rhs) noexcept {
}
/// @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
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.

Constructor & Destructor Documentation

◆ generic_ordering_from_three_way_compare() [1/3]

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

Default constructor is protected.

◆ ~generic_ordering_from_three_way_compare()

template<typename Derived>
arene::base::generic_ordering_from_three_way_compare< Derived >::~generic_ordering_from_three_way_compare ( )
protecteddefaultnoexcept

Default destructor is protected.

◆ generic_ordering_from_three_way_compare() [2/3]

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

Default copy constructor is protected.

Parameters
otherThe source object

◆ generic_ordering_from_three_way_compare() [3/3]

template<typename Derived>
arene::base::generic_ordering_from_three_way_compare< Derived >::generic_ordering_from_three_way_compare ( generic_ordering_from_three_way_compare< 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< Derived >::operator= ( generic_ordering_from_three_way_compare< Derived > && other) & -> generic_ordering_from_three_way_compare &=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< Derived >::operator= ( generic_ordering_from_three_way_compare< Derived > const & other) & -> generic_ordering_from_three_way_compare &=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< 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

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
Precondition
Derived::three_way_compare(rhs,lhs) is well-formed
Other::three_way_compare(lhs,rhs) is not well-formed

◆ 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

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
Precondition
Derived::three_way_compare(lhs,rhs) is well-formed

◆ 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
Precondition
Derived::three_way_compare(rhs,lhs) is well-formed

◆ 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
Precondition
Derived::three_way_compare(lhs,rhs) is well-formed

◆ 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
Precondition
Derived::three_way_compare(rhs,lhs) is well-formed

◆ 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
Precondition
Derived::three_way_compare(lhs,rhs) is well-formed

◆ operator== [1/3]

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

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
Precondition
Derived::three_way_compare(rhs,lhs) is well-formed
Other::three_way_compare(lhs,rhs) is not well-formed

◆ operator== [2/3]

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<!has_fast_inequality_check_v< Derived, Other > > > = nullptr>
ARENE_NODISCARD friend constexpr auto operator== ( Self const & lhs,
Other 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
Precondition
Derived::three_way_compare(lhs,rhs) is well-formed

◆ operator== [3/3]

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< has_fast_inequality_check_v< Derived, Other > > > = nullptr>
ARENE_NODISCARD friend constexpr auto operator== ( Self const & lhs,
Other 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
Precondition
Derived::three_way_compare(lhs,rhs) is well-formed

◆ 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
Precondition
Derived::three_way_compare(rhs,lhs) is well-formed

◆ 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
Precondition
Derived::three_way_compare(lhs,rhs) is well-formed

◆ 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
Precondition
Derived::three_way_compare(rhs,lhs) is well-formed

◆ 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
Precondition
Derived::three_way_compare(lhs,rhs) is well-formed

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