Index: ChangeLog
from Damien Thivolle <damien(a)lrde.epita.fr>
* mlc/cmp.hh: Add comparison traits (greatereq, greater, neq, ...).
cmp.hh | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 81 insertions(+), 1 deletion(-)
Index: mlc/cmp.hh
--- mlc/cmp.hh (revision 59)
+++ mlc/cmp.hh (working copy)
@@ -32,11 +32,16 @@
# include <mlc/bool.hh>
-namespace mlc
+namespace mlc
{
namespace type {
+ /*-----------------.
+ | Type comparisons |
+ `-----------------*/
+
+
template <typename T, typename U>
struct eq : returns_bool_<false> {};
@@ -45,7 +50,82 @@
} // end of namespace type
+ /*-------------------.
+ | Values comparisons |
+ `-------------------*/
+ // These struct are quite handy since constructions like
+ // is_true<a < b>::ensure() cannot be parsed.
+
+ template<int i, int j>
+ struct less
+ {
+ enum { ret = (i < j) };
+ static void ensure() { is_true<ret>::ensure(); };
+ };
+
+ template<int i, int j>
+ struct lesseq
+ {
+ enum { ret = (i <= j) };
+ static void ensure() { is_true<ret>::ensure(); };
+ };
+
+ template<int i, int j>
+ struct eq
+ {
+ enum { ret = (i == j) };
+ static void ensure() { is_true<ret>::ensure(); };
+ };
+
+ template<int i, int j>
+ struct neq
+ {
+ enum { ret = (i != j) };
+ static void ensure() { is_true<ret>::ensure(); };
+ };
+
+ template<int i, int j>
+ struct greater
+ {
+ enum { ret = (i > j) };
+ static void ensure() { is_true<ret>::ensure(); };
+ };
+
+ template<int i, int j>
+ struct greatereq
+ {
+ enum { ret = (i >= j) };
+ static void ensure() { is_true<ret>::ensure(); };
+ };
+
+ template<int i, int j>
+ struct min
+ {
+ enum { ret = (i < j ? i : j) };
+ };
+
+ template<int i, int j>
+ struct max
+ {
+ enum { ret = (i > j ? i : j) };
+ };
+
+ template<int i, int j, int N>
+ struct maxN
+ {
+ enum { ret = (i > j ?
+ (i > N ? N : i) :
+ (j > N ? N : j)) };
+ };
+
+ template<int i, int N>
+ struct saturateN
+ {
+ enum { ret = (i > N ? N : i) };
+ };
+
+
} // end of namespace mlc