فهرست منبع

wip: make shared traits usable

Michele Caini 7 سال پیش
والد
کامیت
f7c756d215
4فایلهای تغییر یافته به همراه52 افزوده شده و 29 حذف شده
  1. 39 29
      src/entt/core/type_traits.hpp
  2. 5 0
      test/lib/a_module.cpp
  3. 5 0
      test/lib/another_module.cpp
  4. 3 0
      test/lib/lib.cpp

+ 39 - 29
src/entt/core/type_traits.hpp

@@ -44,41 +44,20 @@ struct shared_traits;
 
 
 
 
 /**
 /**
- * @brief Makes an already existing type a shared type.
- * @param type Type to make shareable.
- */
-#define ENTT_SHARED_TYPE(type)\
-    template<>\
-    struct shared_traits<type>\
-        : std::integral_constant<typename hashed_string::hash_type, hashed_string::to_value(#type)>\
-    {}
-
-
-/**
- * @brief Defines a type as shareable (to use for structs).
- * @param clazz Name of the type to make shareable.
- */
-#define ENTT_SHARED_STRUCT(clazz)\
-    struct clazz;\
-    ENTT_SHARED_TYPE(clazz)\
-    struct clazz
-
-
-/**
- * @brief Defines a type as shareable (to use for classes).
- * @param clazz Name of the type to make shareable.
+ * @brief Specialization used to get rid of constness.
+ * @tparam Type Shared type.
  */
  */
-#define ENTT_SHARED_CLASS(clazz)\
-    class clazz;\
-    ENTT_SHARED_TYPE(clazz)\
-    class clazz
+template<typename Type>
+struct shared_traits<const Type>
+        : shared_traits<Type>
+{};
 
 
 
 
 /**
 /**
  * @brief Provides the member constant `value` to true if a given type is
  * @brief Provides the member constant `value` to true if a given type is
  * shared. In all other cases, `value` is false.
  * shared. In all other cases, `value` is false.
  */
  */
-template<typename>
+template<typename, typename = std::void_t<>>
 struct is_shared: std::false_type {};
 struct is_shared: std::false_type {};
 
 
 
 
@@ -88,7 +67,7 @@ struct is_shared: std::false_type {};
  * @tparam Type Potentially shared type.
  * @tparam Type Potentially shared type.
  */
  */
 template<typename Type>
 template<typename Type>
-struct is_shared<shared_traits<Type>>: std::true_type {};
+struct is_shared<Type, std::void_t<typename shared_traits<std::decay_t<Type>>::type>>: std::true_type {};
 
 
 
 
 /**
 /**
@@ -105,4 +84,35 @@ constexpr auto is_shared_v = is_shared<Type>::value;
 }
 }
 
 
 
 
+/**
+ * @brief Makes an already existing type a shared type.
+ * @param type Type to make shareable.
+ */
+#define ENTT_SHARED_TYPE(type)\
+    template<>\
+    struct entt::shared_traits<type>\
+        : std::integral_constant<typename entt::hashed_string::hash_type, entt::hashed_string::to_value(#type)>\
+    {}
+
+
+/**
+ * @brief Defines a type as shareable (to use for structs).
+ * @param clazz Name of the type to make shareable.
+ */
+#define ENTT_SHARED_STRUCT(clazz)\
+    struct clazz;\
+    ENTT_SHARED_TYPE(clazz)\
+    struct clazz
+
+
+/**
+ * @brief Defines a type as shareable (to use for classes).
+ * @param clazz Name of the type to make shareable.
+ */
+#define ENTT_SHARED_CLASS(clazz)\
+    class clazz;\
+    ENTT_SHARED_TYPE(clazz)\
+    class clazz
+
+
 #endif // ENTT_CORE_TYPE_TRAITS_HPP
 #endif // ENTT_CORE_TYPE_TRAITS_HPP

+ 5 - 0
test/lib/a_module.cpp

@@ -10,6 +10,11 @@
 #endif
 #endif
 #endif
 #endif
 
 
+ENTT_SHARED_TYPE(int);
+ENTT_SHARED_TYPE(char);
+ENTT_SHARED_TYPE(double);
+ENTT_SHARED_TYPE(float);
+
 LIB_EXPORT typename entt::registry<>::component_type a_module_int_type() {
 LIB_EXPORT typename entt::registry<>::component_type a_module_int_type() {
     entt::registry<> registry;
     entt::registry<> registry;
 
 

+ 5 - 0
test/lib/another_module.cpp

@@ -10,6 +10,11 @@
 #endif
 #endif
 #endif
 #endif
 
 
+ENTT_SHARED_TYPE(int);
+ENTT_SHARED_TYPE(char);
+ENTT_SHARED_TYPE(double);
+ENTT_SHARED_TYPE(float);
+
 LIB_EXPORT typename entt::registry<>::component_type another_module_int_type() {
 LIB_EXPORT typename entt::registry<>::component_type another_module_int_type() {
     entt::registry<> registry;
     entt::registry<> registry;
 
 

+ 3 - 0
test/lib/lib.cpp

@@ -6,6 +6,9 @@ extern typename entt::registry<>::component_type a_module_char_type();
 extern typename entt::registry<>::component_type another_module_int_type();
 extern typename entt::registry<>::component_type another_module_int_type();
 extern typename entt::registry<>::component_type another_module_char_type();
 extern typename entt::registry<>::component_type another_module_char_type();
 
 
+ENTT_SHARED_TYPE(int);
+ENTT_SHARED_TYPE(char);
+
 TEST(Lib, Shared) {
 TEST(Lib, Shared) {
     entt::registry<> registry;
     entt::registry<> registry;