Преглед изворни кода

Allow dimensionless multiplication and division for opaque_typedefs generated by macro.

Sam Jaffe пре 7 година
родитељ
комит
129d2eae1b
1 измењених фајлова са 23 додато и 8 уклоњено
  1. 23 8
      opaque_typedef.hpp

+ 23 - 8
opaque_typedef.hpp

@@ -66,8 +66,8 @@ using underlying_type = decltype(underlying_type_impl(std::declval<T>()));
     } \
     \
     friend TDef operator op(TDef const & lhs, RDef const & rhs) { \
-      using type1 = std::underlying_type<TDef>; \
-      using type2 = std::underlying_type<RDef>; \
+      using type1 = underlying_type<TDef>; \
+      using type2 = underlying_type<RDef>; \
       return TDef(static_cast<type1 const&>(lhs) op static_cast<type2 const&>(rhs)); \
     } \
   }
@@ -113,14 +113,21 @@ OPAQUE_TYPE_ASSIGN_OPERATOR(exclusive_or, ^);
 #undef OPAQUE_TYPE_ASSIGN_OPERATOR
 
 template <typename TDef>
-struct dimensional_arithmetic : unary_plus<TDef>, unary_minus<TDef>, addition<TDef>, subtraction<TDef> {};
+struct arithmetic : unary_plus<TDef>, unary_minus<TDef>, addition<TDef>, subtraction<TDef> {};
 
 template <typename TDef>
-struct numeric_arithmetic : dimensional_arithmetic<TDef>, multiplication<TDef>, division<TDef> {};
+struct numeric_arithmetic : arithmetic<TDef>, multiplication<TDef>, division<TDef> {};
 
 template <typename TDef>
 struct integer_arithmetic : numeric_arithmetic<TDef>, modulo<TDef> {};
 
+template <typename TDef, typename Base = underlying_type<TDef>>
+struct untyped_multiplication : mixed_multiplication<TDef, Base, TDef>
+, mixed_multiplication<Base, TDef, TDef> {};
+
+template <typename TDef, typename Base = underlying_type<TDef>>
+struct untyped_division : mixed_division<TDef, Base, TDef> {};
+
 template <typename TDef>
 struct equality_comparible : equals<TDef>, not_equals<TDef> {};
 
@@ -156,17 +163,25 @@ private:
   }
 
 #define CREATE_CONVERTABLE_OPAQUE_TYPEDEF(name, basetype, ...) \
-  struct name : opaque_typedef<name, basetype> \
-  BOOST_PP_SEQ_FOR_EACH(OPAQUE_TYPEDEF_PARENT, name, BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__)) \
+  struct name##_base : opaque_typedef<name, basetype> \
   { \
     using opaque_typedef::opaque_typedef; \
+  }; \
+  struct name : name##_base \
+  BOOST_PP_SEQ_FOR_EACH(OPAQUE_TYPEDEF_PARENT, name##_base, BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__)) \
+  { \
+    using name##_base::name##_base; \
     OPAQUE_TYPEDEF_CONVERSIONS
 
 
 #define OPAQUE_TYPEDEF_PARENT(r, name, parent) , parent < name >
 #define CREATE_OPAQUE_TYPEDEF(name, basetype, ...) \
-  struct name : opaque_typedef<name, basetype> \
-  BOOST_PP_SEQ_FOR_EACH(OPAQUE_TYPEDEF_PARENT, name, BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__)) \
+  struct name##_base : opaque_typedef<name, basetype> \
   { \
     using opaque_typedef::opaque_typedef; \
+  }; \
+  struct name : name##_base \
+  BOOST_PP_SEQ_FOR_EACH(OPAQUE_TYPEDEF_PARENT, name##_base, BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__)) \
+  { \
+    using name##_base::name##_base; \
   }