ORIGINAL
Loading...
Searching...
No Matches
original::CmpTraits Concept Reference

Requires type to implement the comparable interface with compareTo method. More...

#include <types.h>

Concept definition

template<typename T>
concept original::CmpTraits = requires(const T& a, const T& b) {
{ a.compareTo(b) } -> std::same_as<integer>;
}
Requires type to implement the comparable interface with compareTo method.
Definition types.h:190

Detailed Description

Requires type to implement the comparable interface with compareTo method.

Template Parameters
TThe type to check

This concept enforces that a type provides a Java-style comparison interface through a compareTo method that returns an integer indicating ordering. Types satisfying this concept can be used with the comparable base class and benefit from automatically generated comparison operators.

Requirements:

// Example of a type satisfying CmpTraits
class MyComparable {
public:
integer compareTo(const MyComparable& other) const {
return this->value - other.value;
}
// Automatically gets ==, !=, <, >, <=, >= operators
private:
int value;
};
static_assert(CmpTraits<MyComparable>); // Succeeds
See also
comparable