memgraph/src/utils/total_ordering.hpp
Dominik Gleich 07d262cd1e Add virtual destructors
Summary:
Virtual destructors were missing in classes/structs which can
be inherited.
A missing virtual destructor gives undefined behaviour when
deleting derived class using base type.

Reviewers: teon.banek

Reviewed By: teon.banek

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D1117
2018-01-19 10:40:09 +01:00

69 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 {
virtual ~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 {
virtual ~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);
}
};