From fa7d07bf01142e5ed4b5d85f0408ec2b0e9c8be5 Mon Sep 17 00:00:00 2001 From: q66 Date: Sat, 11 Jul 2015 22:05:02 +0100 Subject: [PATCH] tuple relational operators --- octa/tuple.hh | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) 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