Jelajahi Sumber

meta: internal change

Michele Caini 1 tahun lalu
induk
melakukan
41e91688da
2 mengubah file dengan 7 tambahan dan 4 penghapusan
  1. 1 1
      TODO
  2. 6 3
      src/entt/meta/meta.hpp

+ 1 - 1
TODO

@@ -31,5 +31,5 @@ TODO:
 * allow passing arguments to meta setter/getter (we can fallback on meta invoke probably)
 * FetchContent_Populate -> FetchContent_MakeAvailable warnings
 * doc: IMPLICIT_DIR_DOCS for dir docs or \dir
-* meta non-const allow_cast overloads: (const int &) to (int &) is not allowed, but (const int &) to (double &) is allowed
+* meta non-const allow_cast overloads: (const int &) to (int &) is not allowed, but (const int &) to (double &) is allowed (support only for convertibles)
 * improve non-const allow cast with in-place switch

+ 6 - 3
src/entt/meta/meta.hpp

@@ -526,9 +526,12 @@ public:
      */
     template<typename Type>
     [[nodiscard]] bool allow_cast() {
-        // also support early return for performance reasons
-        return (((node.info != nullptr) && (*node.info == entt::type_id<Type>())) || allow_cast(meta_type{*ctx, internal::resolve<std::remove_cv_t<std::remove_reference_t<Type>>>(internal::meta_context::from(*ctx))}))
-               && (!(std::is_reference_v<Type> && !std::is_const_v<std::remove_reference_t<Type>>) || storage.data() != nullptr);
+        if constexpr(std::is_reference_v<Type> && !std::is_const_v<std::remove_reference_t<Type>>) {
+            return allow_cast<const std::remove_reference_t<Type> &>() && (storage.data() != nullptr);
+        } else {
+            // also support early return for performance reasons
+            return ((node.info != nullptr) && (*node.info == entt::type_id<Type>())) || allow_cast(meta_type{*ctx, internal::resolve<std::remove_cv_t<std::remove_reference_t<Type>>>(internal::meta_context::from(*ctx))});
+        }
     }
 
     /*! @copydoc any::emplace */