memgraph/src/utils/total_ordering.hpp
Mislav Bradac bba20cf89c Remove unneccessary files from utils
Reviewers: buda

Reviewed By: buda

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D276
2017-04-13 17:55:33 +02:00

65 lines
1.6 KiB
C++

#pragma once
/**
* Implements all the logical comparison operators based on '=='
* and '<' operators.
*
* @tparam TLhs First operand type.
* @tparam TRhs Second operand type. Defaults to the same type
* as first operand.
* @tparam TReturn Return type, defaults to bool.
*/
template <typename TLhs, typename TRhs = TLhs, typename TReturn = bool>
struct TotalOrdering {
friend constexpr TReturn operator!=(const TLhs& a, const TRhs& b) {
return !(a == b);
}
friend constexpr TReturn operator<=(const TLhs& a, const TRhs& b) {
return a < b || a == b;
}
friend constexpr TReturn operator>(const TLhs& a, const TRhs& b) {
return !(a <= b);
}
friend constexpr TReturn operator>=(const TLhs& a, const TRhs& b) {
return !(a < b);
}
};
template <class Derived, class T>
struct TotalOrderingWith {
friend constexpr bool operator!=(const Derived& a, const T& b) {
return !(a == b);
}
friend constexpr bool operator<=(const Derived& a, const T& b) {
return a < b || a == b;
}
friend constexpr bool operator>(const Derived& a, const T& b) {
return !(a <= b);
}
friend constexpr bool operator>=(const Derived& a, const T& b) {
return !(a < b);
}
friend constexpr bool operator!=(const T& a, const Derived& b) {
return !(a == b);
}
friend constexpr bool operator<=(const T& a, const Derived& b) {
return a < b || a == b;
}
friend constexpr bool operator>(const T& a, const Derived& b) {
return !(a <= b);
}
friend constexpr bool operator>=(const T& a, const Derived& b) {
return !(a < b);
}
};