Browse Source

Break out impl files from opaque_typedef.

Sam Jaffe 5 năm trước cách đây
mục cha
commit
6b05c16210

+ 29 - 0
include/opaque_typedef/comparable.hpp

@@ -0,0 +1,29 @@
+#pragma once
+
+namespace types {
+  template <typename Self>
+  struct EqualityComparable {
+    friend bool operator==(Self const & lhs, Self const & rhs) {
+      return lhs.get() == rhs.get();
+    }
+    friend bool operator!=(Self const & lhs, Self const & rhs) {
+      return !(lhs == rhs);
+    }
+  };
+  
+  template <typename Self>
+  struct Comparable : EqualityComparable<Self> {
+    friend bool operator<(Self const & lhs, Self const & rhs) {
+      return lhs.get() < rhs.get();
+    }
+    friend bool operator>(Self const & lhs, Self const & rhs) {
+      return rhs.get() < lhs.get();
+    }
+    friend bool operator<=(Self const & lhs, Self const & rhs) {
+      return !(rhs.get() < lhs.get());
+    }
+    friend bool operator>=(Self const & lhs, Self const & rhs) {
+      return !(lhs.get() < rhs.get());
+    }
+  };
+}

+ 16 - 0
include/opaque_typedef/convertable.hpp

@@ -0,0 +1,16 @@
+#pragma once
+
+namespace types {
+  
+  template <typename To>
+  struct Convertable {
+    template <typename Self>
+    class type {
+    private:
+      Self const & self() const { return *(Self const *)(void const *)(this); }
+    public:
+      operator To() const;
+    };
+  };
+  
+}

+ 2 - 45
include/opaque_typedef/opaque_typedef.hpp

@@ -9,16 +9,8 @@
 
 #pragma once
 
-#include <type_traits>
-
-namespace types { namespace detail {
-  template <typename FromOpaque>
-  struct is_a {
-    FromOpaque const & self() const {
-      return *(FromOpaque const *)(void const *)(this);
-    }
-  };
-}}
+#include "comparable.hpp"
+#include "convertable.hpp"
 
 namespace types {
   template <typename Base, typename Tag, template <typename> class... Skills>
@@ -37,39 +29,4 @@ namespace types {
     Base const & get() const { return value_; }
     explicit operator Base const &() const { return value_; }
   };
-  
-  template <typename Opaque>
-  struct EqualityComparable {
-    friend bool operator==(Opaque const & lhs, Opaque const & rhs) {
-      return lhs.get() == rhs.get();
-    }
-    friend bool operator!=(Opaque const & lhs, Opaque const & rhs) {
-      return !(lhs == rhs);
-    }
-  };
-  
-  template <typename Opaque>
-  struct Comparable : EqualityComparable<Opaque> {
-    friend bool operator<(Opaque const & lhs, Opaque const & rhs) {
-      return lhs.get() < rhs.get();
-    }
-    friend bool operator>(Opaque const & lhs, Opaque const & rhs) {
-      return rhs.get() < lhs.get();
-    }
-    friend bool operator<=(Opaque const & lhs, Opaque const & rhs) {
-      return !(rhs.get() < lhs.get());
-    }
-    friend bool operator>=(Opaque const & lhs, Opaque const & rhs) {
-      return !(lhs.get() < rhs.get());
-    }
-  };
-  
-  template <typename ToOpaque>
-  struct Convertable {
-    template <typename FromOpaque>
-    class type : detail::is_a<FromOpaque> {
-    public:
-      operator ToOpaque() const;
-    };
-  };
 }