]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common: WRITE_{EQ,CMP}_OPERATORS_1
authorLoic Dachary <loic@dachary.org>
Wed, 28 May 2014 12:53:47 +0000 (14:53 +0200)
committerLoic Dachary <loic@dachary.org>
Thu, 29 May 2014 19:53:19 +0000 (21:53 +0200)
For when a struct is defined to encapsulate a single value and get
control over implicit conversions that would otherwise be impossible
with typedef.

Signed-off-by: Loic Dachary <loic@dachary.org>
src/include/cmp.h

index 92ecef47990453a4aa2796983aa1fdfeb0747f52..93365bf6ac62797d4766104fce9264e9f725676d 100644 (file)
@@ -5,6 +5,28 @@
  * macros to define comparison operators for classes with small numbers of members.
  */
 
+#define WRITE_EQ_OPERATORS_1(type, a)                                  \
+  inline bool operator==(const type &l, const type &r) {               \
+    return l.a == r.a;                                                 \
+  }                                                                    \
+  inline bool operator!=(const type &l, const type &r) {               \
+    return l.a != r.a;                                                 \
+  }
+
+#define WRITE_CMP_OPERATORS_1(type, a)                                 \
+  inline bool operator>(const type &l, const type &r) {                        \
+    return l.a > r.a;                                                  \
+  }                                                                    \
+  inline bool operator<(const type &l, const type &r) {                        \
+    return l.a < r.a;                                                  \
+  }                                                                    \
+  inline bool operator>=(const type &l, const type &r) {               \
+    return l.a >= r.a;                                                 \
+  }                                                                    \
+  inline bool operator<=(const type &l, const type &r) {               \
+    return l.a <= r.a;                                                 \
+  }
+
 #define WRITE_EQ_OPERATORS_2(type, a, b)                               \
   inline bool operator==(const type &l, const type &r) {               \
     return l.a == r.a && l.b == r.b;                                   \