ORIGINAL
Loading...
Searching...
No Matches
Classes | Namespaces | Functions
comparable.h File Reference

Interface for objects that can be compared. More...

#include "config.h"
#include "types.h"
#include <compare>
Include dependency graph for comparable.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  original::comparable< DERIVED >
 Base class for comparable objects. More...
 

Namespaces

namespace  original
 Main namespace for the project Original.
 

Functions

template<original::CmpTraits T>
std::strong_ordering operator<=> (const T &lhs, const T &rhs)
 Three-way comparison operator for CmpTraits types.
 

Detailed Description

Interface for objects that can be compared.

Defines an interface for comparing instances of derived classes. Derived classes must implement compareTo() to provide comparison logic. Provides common comparison operators for convenience.

Function Documentation

◆ operator<=>()

template<original::CmpTraits T>
std::strong_ordering operator<=> ( const T &  lhs,
const T &  rhs 
)

Three-way comparison operator for CmpTraits types.

Template Parameters
TType satisfying CmpTraits concept
Parameters
lhsLeft-hand side object
rhsRight-hand side object
Returns
std::strong_ordering result based on compareTo()

Provides C++20 spaceship operator support for types implementing the comparable interface. Enables modern comparison syntax.

Example:

class MyComparable : public original::comparable<MyComparable> {
integer compareTo(const MyComparable& other) const override { ... }
};
MyComparable a, b;
auto result = a <=> b; // Uses this operator
Base class for comparable objects.
Definition comparable.h:35
virtual integer compareTo(const DERIVED &other) const =0
Compares the current object with another of the same type.