|
virtual integer | compareTo (const DERIVED &other) const =0 |
| Compares the current object with another of the same type.
|
|
bool | operator== (const DERIVED &other) const |
| Checks if the current object is equal to another.
|
|
bool | operator!= (const DERIVED &other) const |
| Checks if the current object is not equal to another.
|
|
bool | operator< (const DERIVED &other) const |
| Checks if the current object is less than another.
|
|
bool | operator> (const DERIVED &other) const |
| Checks if the current object is greater than another.
|
|
bool | operator<= (const DERIVED &other) const |
| Checks if the current object is less than or equal to another.
|
|
bool | operator>= (const DERIVED &other) const |
| Checks if the current object is greater than or equal to another.
|
|
virtual | ~comparable ()=default |
| Virtual destructor for proper cleanup of derived objects.
|
|
template<typename DERIVED>
class original::comparable< DERIVED >
Base class for comparable objects.
- Template Parameters
-
DERIVED | The type of the derived class. |
This class defines a compareTo()
method that must be implemented by derived classes to compare their instances. It also provides common comparison operators (==
, !=
, <
, >
, <=
, >=
) based on the compareTo()
method.
Derived classes are expected to override compareTo()
to return:
- A negative value if the current object is less than the other.
- Zero if the current object is equal to the other.
- A positive value if the current object is greater than the other.
template<typename DERIVED>
template<typename EXTENDED>
std::strong_ordering operator<=> |
( |
const EXTENDED & | lc, |
|
|
const EXTENDED & | rc ) |
|
friend |
Three-way comparison operator (<=>), returns an ordered comparison result.
This operator is implemented by invoking the compareTo() method of the comparable object. The result type is std::strong_ordering, indicating strong ordering semantics. Defined as a friend function to enable symmetric argument handling.
- Template Parameters
-
EXTENDED | The actual derived type using CRTP pattern. |
- Parameters
-
lc | Left-hand side comparable object |
rc | Right-hand side comparable object |
- Returns
- std::strong_ordering
- std::strong_ordering::less if lhs < rhs
- std::strong_ordering::equal if lhs == rhs
- std::strong_ordering::greater if lhs > rhs