Ver código fonte

meta: support deducing meta pointer like types directly

Michele Caini 1 ano atrás
pai
commit
91a6837d6a

+ 0 - 3
TODO

@@ -24,11 +24,8 @@ TODO:
 * review cmake warning about FetchContent_Populate (need .28 and EXCLUDE_FROM_ALL for FetchContent)
 * suppress -Wself-move on CI with g++13
 * view specializations for multi, single and filtered elements
-* meta range: move id to meta objects and return plain types (?), then remove id from meta base and meta ctor too
 * don't pass reactive storage by default to callback
 * runtime types support for meta for types that aren't backed by C++ types
 * built-in no-pagination storage - no_pagination page size as limits::max
 * any cdynamic to support const ownership construction
 * allow passing arguments to meta setter/getter (we can fallback on meta invoke probably)
-* meta: review/update rebind policy for handles and arguments
-* try to specialize things like is_pointer_like from the type directly if possible

+ 8 - 0
docs/md/meta.md

@@ -541,6 +541,14 @@ some common classes. In particular:
 
 * All types of raw pointers.
 * `std::unique_ptr` and `std::shared_ptr`.
+* All classes that _export_ a type member called `is_meta_pointer_like`:
+  ```cpp
+  struct smart_pointer {
+      using is_meta_pointer_like = void;
+      // ...
+  };
+  ```
+  The actual type is irrelevant and will not be used in any way.
 
 It is important to include the header file `pointer.hpp` to make these
 specializations available to the compiler when needed.<br/>

+ 8 - 0
src/entt/meta/pointer.hpp

@@ -46,6 +46,14 @@ template<typename Type, typename... Args>
 struct is_meta_pointer_like<std::unique_ptr<Type, Args...>>
     : std::true_type {};
 
+/**
+ * @brief Specialization for self-proclaimed meta pointer like types.
+ * @tparam Type Element type.
+ */
+template<typename Type>
+struct is_meta_pointer_like<Type, std::void_t<typename Type::is_meta_pointer_like>>
+    : std::true_type {};
+
 } // namespace entt
 
 #endif

+ 1 - 1
src/entt/meta/type_traits.hpp

@@ -31,7 +31,7 @@ struct meta_associative_container_traits;
  * @brief Provides the member constant `value` to true if a given type is a
  * pointer-like type from the point of view of the meta system, false otherwise.
  */
-template<typename>
+template<typename, typename = void>
 struct is_meta_pointer_like: std::false_type {};
 
 /**

+ 6 - 8
test/entt/meta/meta_pointer.cpp

@@ -49,16 +49,14 @@ struct proxy_ptr {
 };
 
 template<typename Type>
-struct adl_wrapped_shared_ptr: wrapped_shared_ptr<Type> {};
-
-template<typename Type>
-struct spec_wrapped_shared_ptr: wrapped_shared_ptr<Type> {};
-
-template<typename Type>
-struct entt::is_meta_pointer_like<adl_wrapped_shared_ptr<Type>>: std::true_type {};
+struct adl_wrapped_shared_ptr: wrapped_shared_ptr<Type> {
+    using is_meta_pointer_like = void;
+};
 
 template<typename Type>
-struct entt::is_meta_pointer_like<spec_wrapped_shared_ptr<Type>>: std::true_type {};
+struct spec_wrapped_shared_ptr: wrapped_shared_ptr<Type> {
+    using is_meta_pointer_like = void;
+};
 
 template<>
 struct entt::is_meta_pointer_like<self_ptr>: std::true_type {};