diff --git a/octa/tuple.hh b/octa/tuple.hh index 3bb31ba..e6684ee 100644 --- a/octa/tuple.hh +++ b/octa/tuple.hh @@ -480,6 +480,77 @@ inline Tuple forward_as_tuple(T &&...t) { return Tuple(forward(t)...); } +/* tuple relops */ + +namespace detail { + template + struct TupleEqual { + template + bool operator()(const T &x, const U &y) { + return TupleEqual()(x, y) && (get(x) == get(y)); + } + }; + + template<> + struct TupleEqual<0> { + template + bool operator()(const T &, const U &) { + return true; + } + }; +} + +template +inline bool operator==(const Tuple &x, const Tuple &y) { + return detail::TupleEqual(x, y); +} + +template +inline bool operator!=(const Tuple &x, const Tuple &y) { + return !(x == y); +} + +namespace detail { + template + struct TupleLess { + template + bool operator()(const T &x, const U &y) { + Size J = TupleSize::value - I; + if (get(x) < get(y)) return true; + if (get(y) < get(x)) return false; + return TupleLess()(x, y); + } + }; + + template<> + struct TupleLess<0> { + template + bool operator()(const T &, const U &) { + return true; + } + }; +} + +template +inline bool operator<(const Tuple &x, const Tuple &y) { + return detail::TupleLess(x, y); +} + +template +inline bool operator>(const Tuple &x, const Tuple &y) { + return y < x; +} + +template +inline bool operator<=(const Tuple &x, const Tuple &y) { + return !(y < x); +} + +template +inline bool operator>=(const Tuple &x, const Tuple &y) { + return !(x < y); +} + } /* namespace octa */ #endif \ No newline at end of file