ORIGINAL
Loading...
Searching...
No Matches
comparable.h
Go to the documentation of this file.
1#ifndef COMPARABLE_H
2#define COMPARABLE_H
3#include "config.h"
4#include "types.h"
5#include <compare>
6
7
8namespace original {
9
34template <typename DERIVED>
36public:
42 virtual integer compareTo(const DERIVED &other) const = 0;
43
49 bool operator==(const DERIVED &other) const;
50
56 bool operator!=(const DERIVED &other) const;
57
63 bool operator<(const DERIVED &other) const;
64
70 bool operator>(const DERIVED &other) const;
71
77 bool operator<=(const DERIVED &other) const;
78
84 bool operator>=(const DERIVED &other) const;
85
89 virtual ~comparable() = default;
90};
91
92// ----------------- Definitions of comparable.h -----------------
93
94template<typename DERIVED>
95auto comparable<DERIVED>::operator==(const DERIVED &other) const -> bool {
96 return compareTo(other) == 0;
97}
98
99template<typename DERIVED>
101 return compareTo(other) != 0;
102}
103
104template<typename DERIVED>
105auto comparable<DERIVED>::operator<(const DERIVED &other) const -> bool {
106 return compareTo(other) < 0;
107}
108
109template<typename DERIVED>
110auto comparable<DERIVED>::operator>(const DERIVED &other) const -> bool {
111 return compareTo(other) > 0;
112}
113
114template<typename DERIVED>
116 return compareTo(other) <= 0;
117}
118
119template<typename DERIVED>
121 return compareTo(other) >= 0;
122}
123
124} // namespace original
125
145template <original::CmpTraits T>
146std::strong_ordering operator<=>(const T& lhs, const T& rhs)
147{
148 return lhs.compareTo(rhs) <=> 0;
149}
150
151#endif //COMPARABLE_H
integer compareTo(const autoPtr &other) const override
Compare reference counters.
Definition autoPtr.h:714
Base class for comparable objects.
Definition comparable.h:35
bool operator<=(const DERIVED &other) const
Checks if the current object is less than or equal to another.
Definition comparable.h:115
bool operator!=(const DERIVED &other) const
Checks if the current object is not equal to another.
Definition comparable.h:100
bool operator>=(const DERIVED &other) const
Checks if the current object is greater than or equal to another.
Definition comparable.h:120
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.
Definition comparable.h:95
virtual ~comparable()=default
Virtual destructor for proper cleanup of derived objects.
bool operator>(const DERIVED &other) const
Checks if the current object is greater than another.
Definition comparable.h:110
bool operator<(const DERIVED &other) const
Checks if the current object is less than another.
Definition comparable.h:105
Unique ownership smart pointer with move semantics.
Definition ownerPtr.h:37
std::strong_ordering operator<=>(const T &lhs, const T &rhs)
Three-way comparison operator for CmpTraits types.
Definition comparable.h:146
Platform-independent type definitions and compiler/platform detection.
std::int64_t integer
64-bit signed integer type for arithmetic operations
Definition config.h:254
Main namespace for the project Original.
Definition algorithms.h:21
Core type system foundations and concept definitions.