diff --git a/TODO b/TODO index 00753a3b8..c3218cda7 100644 --- a/TODO +++ b/TODO @@ -28,7 +28,6 @@ Next: - meta: update doc - static constexpr -> inline constexpr - remove internal::find_if - - add meta_handle::operator-> that returns a meta_any * (easier to use directly) - use a dedicate class template to specialize meta views for a better support to customizations - - remove operator* from meta_any, meta_handle - add const meta container support to meta any + - meta_any deref fails if operator* returns a temporary diff --git a/src/entt/meta/internal.hpp b/src/entt/meta/internal.hpp index 448e05a4f..6dcf0b9ef 100644 --- a/src/entt/meta/internal.hpp +++ b/src/entt/meta/internal.hpp @@ -164,6 +164,8 @@ public: } friend void swap(meta_storage &lhs, meta_storage &rhs) { + using std::swap; + if(lhs.steal_fn && rhs.steal_fn) { meta_storage buffer{}; lhs.steal_fn(buffer, lhs); @@ -174,12 +176,12 @@ public: } else if(rhs.steal_fn) { rhs.steal_fn(lhs, rhs); } else { - std::swap(lhs.instance, rhs.instance); + swap(lhs.instance, rhs.instance); } - std::swap(lhs.destroy_fn, rhs.destroy_fn); - std::swap(lhs.copy_fn, rhs.copy_fn); - std::swap(lhs.steal_fn, rhs.steal_fn); + swap(lhs.destroy_fn, rhs.destroy_fn); + swap(lhs.copy_fn, rhs.copy_fn); + swap(lhs.steal_fn, rhs.steal_fn); } private: diff --git a/src/entt/meta/meta.hpp b/src/entt/meta/meta.hpp index 1f65cf0a5..8eb88c8d0 100644 --- a/src/entt/meta/meta.hpp +++ b/src/entt/meta/meta.hpp @@ -504,10 +504,11 @@ public: * @param rhs A valid meta any object. */ friend void swap(meta_any &lhs, meta_any &rhs) { - std::swap(lhs.node, rhs.node); - std::swap(lhs.storage, rhs.storage); - std::swap(lhs.deref, rhs.deref); - std::swap(lhs.cview, rhs.cview); + using std::swap; + swap(lhs.node, rhs.node); + swap(lhs.storage, rhs.storage); + swap(lhs.deref, rhs.deref); + swap(lhs.cview, rhs.cview); } private: diff --git a/test/entt/meta/meta_any.cpp b/test/entt/meta/meta_any.cpp index 64436f8d6..0bd5358d5 100644 --- a/test/entt/meta/meta_any.cpp +++ b/test/entt/meta/meta_any.cpp @@ -636,6 +636,27 @@ TEST_F(MetaAny, DereferenceOperatorInvalidType) { ASSERT_FALSE(deref); } +TEST_F(MetaAny, DereferenceOperatorConstType) { + const int value = 0; + entt::meta_any any{&value}; + + ASSERT_TRUE(any.type().is_pointer()); + ASSERT_TRUE(any.type().is_dereferenceable()); + ASSERT_EQ(any.type(), entt::resolve()); + + auto deref = *any; + + ASSERT_TRUE(deref); + ASSERT_FALSE(deref.type().is_pointer()); + ASSERT_FALSE(deref.type().is_dereferenceable()); + ASSERT_EQ(deref.type(), entt::resolve()); + + deref.cast() = 42; + + ASSERT_EQ(*any.cast(), 0); + ASSERT_EQ(value, 0); +} + TEST_F(MetaAny, DereferenceOperatorRawPointer) { int value = 0; entt::meta_any any{&value};