Kaynağa Gözat

meta: not going to drop policy anymore, we can use it safely

skypjack 4 ay önce
ebeveyn
işleme
5e6ccdedc8
2 değiştirilmiş dosya ile 13 ekleme ve 1 silme
  1. 1 1
      src/entt/meta/meta.hpp
  2. 12 0
      test/entt/meta/meta_any.cpp

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

@@ -1417,7 +1417,7 @@ public:
 
         if(const auto &ref = fetch_node(); ref.details) {
             if(auto *elem = internal::find_member<&internal::meta_func_node::id>(ref.details->func, id); elem != nullptr) {
-                if(const auto *candidate = lookup(args, sz, std::is_const_v<std::remove_reference_t<Instance>>, [curr = elem]() mutable { return (curr != nullptr) ? std::exchange(curr, curr->next.get()) : nullptr; }); candidate) {
+                if(const auto *candidate = lookup(args, sz, (wrapped->base().policy() == any_policy::cref), [curr = elem]() mutable { return (curr != nullptr) ? std::exchange(curr, curr->next.get()) : nullptr; }); candidate) {
                     return candidate->invoke(std::move(wrapped), args);
                 }
             }

+ 12 - 0
test/entt/meta/meta_any.cpp

@@ -149,6 +149,7 @@ TEST_F(MetaAny, SBO) {
 
     ASSERT_TRUE(any);
     ASSERT_TRUE(any.base().owner());
+    ASSERT_EQ(any.base().policy(), entt::any_policy::embedded);
     ASSERT_FALSE(any.try_cast<std::size_t>());
     ASSERT_EQ(any.cast<char>(), 'c');
     ASSERT_NE(any.base().data(), nullptr);
@@ -162,6 +163,7 @@ TEST_F(MetaAny, NoSBO) {
 
     ASSERT_TRUE(any);
     ASSERT_TRUE(any.base().owner());
+    ASSERT_EQ(any.base().policy(), entt::any_policy::dynamic);
     ASSERT_FALSE(any.try_cast<std::size_t>());
     ASSERT_EQ(any.cast<fat>(), instance);
     ASSERT_NE(any.base().data(), nullptr);
@@ -176,6 +178,7 @@ TEST_F(MetaAny, SBOInPlaceConstruction) {
 
     ASSERT_TRUE(any);
     ASSERT_TRUE(any.base().owner());
+    ASSERT_EQ(any.base().policy(), entt::any_policy::dynamic);
     ASSERT_FALSE(any.try_cast<std::size_t>());
     ASSERT_EQ(any.cast<int>(), 2);
     ASSERT_NE(any.base().data(), nullptr);
@@ -186,6 +189,7 @@ TEST_F(MetaAny, SBOInPlaceConstruction) {
 
     ASSERT_TRUE(other);
     ASSERT_FALSE(other.base().owner());
+    ASSERT_EQ(other.base().policy(), entt::any_policy::ref);
     ASSERT_FALSE(other.try_cast<std::size_t>());
     ASSERT_EQ(other.cast<int>(), 2);
     ASSERT_NE(other.base().data(), nullptr);
@@ -222,6 +226,7 @@ TEST_F(MetaAny, SBOAsRefConstruction) {
 
     ASSERT_TRUE(any);
     ASSERT_FALSE(any.base().owner());
+    ASSERT_EQ(any.base().policy(), entt::any_policy::ref);
     ASSERT_EQ(any.type(), entt::resolve<int>());
 
     ASSERT_FALSE(any.try_cast<std::size_t>());
@@ -257,6 +262,7 @@ TEST_F(MetaAny, SBOAsConstRefConstruction) {
 
     ASSERT_TRUE(any);
     ASSERT_FALSE(any.base().owner());
+    ASSERT_EQ(any.base().policy(), entt::any_policy::cref);
     ASSERT_EQ(any.type(), entt::resolve<int>());
 
     ASSERT_FALSE(any.try_cast<std::size_t>());
@@ -506,6 +512,7 @@ TEST_F(MetaAny, NoSBOInPlaceConstruction) {
 
     ASSERT_TRUE(any);
     ASSERT_TRUE(any.base().owner());
+    ASSERT_EQ(any.base().policy(), entt::any_policy::dynamic);
     ASSERT_FALSE(any.try_cast<std::size_t>());
     ASSERT_EQ(any.cast<fat>(), instance);
     ASSERT_NE(any.base().data(), nullptr);
@@ -516,6 +523,7 @@ TEST_F(MetaAny, NoSBOInPlaceConstruction) {
 
     ASSERT_TRUE(other);
     ASSERT_FALSE(other.base().owner());
+    ASSERT_EQ(other.base().policy(), entt::any_policy::ref);
     ASSERT_FALSE(other.try_cast<std::size_t>());
     ASSERT_EQ(other.cast<fat>(), instance);
     ASSERT_NE(other.base().data(), nullptr);
@@ -552,6 +560,7 @@ TEST_F(MetaAny, NoSBOAsRefConstruction) {
 
     ASSERT_TRUE(any);
     ASSERT_FALSE(any.base().owner());
+    ASSERT_EQ(any.base().policy(), entt::any_policy::ref);
     ASSERT_EQ(any.type(), entt::resolve<fat>());
 
     ASSERT_FALSE(any.try_cast<std::size_t>());
@@ -585,6 +594,7 @@ TEST_F(MetaAny, NoSBOAsConstRefConstruction) {
 
     ASSERT_TRUE(any);
     ASSERT_FALSE(any.base().owner());
+    ASSERT_EQ(any.base().policy(), entt::any_policy::cref);
     ASSERT_EQ(any.type(), entt::resolve<fat>());
 
     ASSERT_FALSE(any.try_cast<std::size_t>());
@@ -852,6 +862,7 @@ TEST_F(MetaAny, VoidInPlaceTypeConstruction) {
 
     ASSERT_TRUE(any);
     ASSERT_FALSE(any.base().owner());
+    ASSERT_EQ(any.base().policy(), entt::any_policy::empty);
     ASSERT_FALSE(any.try_cast<char>());
     ASSERT_EQ(any.base().data(), nullptr);
     ASSERT_EQ(any.type(), entt::resolve<void>());
@@ -864,6 +875,7 @@ TEST_F(MetaAny, VoidAsRefConstruction) {
 
     ASSERT_TRUE(any);
     ASSERT_FALSE(any.base().owner());
+    ASSERT_EQ(any.base().policy(), entt::any_policy::empty);
     ASSERT_EQ(any.type(), entt::resolve<void>());
 
     ASSERT_FALSE(any.try_cast<std::size_t>());