From 77afd2d36ce9202835166d4eabe4aceaedb10dfe Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Mon, 3 May 2021 00:04:05 +0200 Subject: [PATCH] any: ::owner function (useful to also review meta_any) --- src/entt/core/any.hpp | 26 ++++++--- test/entt/core/any.cpp | 125 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 142 insertions(+), 9 deletions(-) diff --git a/src/entt/core/any.hpp b/src/entt/core/any.hpp index b00834454..8b5f3ad33 100644 --- a/src/entt/core/any.hpp +++ b/src/entt/core/any.hpp @@ -25,7 +25,7 @@ namespace entt { template class basic_any { enum class operation: std::uint8_t { COPY, MOVE, DTOR, COMP, ADDR, CADDR, TYPE }; - enum class policy: std::uint8_t { OWNED, REF, CREF }; + enum class policy: std::uint8_t { OWNER, REF, CREF }; using storage_type = std::aligned_storage_t; using vtable_type = const void *(const operation, const basic_any &, void *); @@ -42,7 +42,7 @@ class basic_any { return policy::REF; } } else { - return policy::OWNED; + return policy::OWNER; } } @@ -60,7 +60,7 @@ class basic_any { static_assert(std::is_same_v>, Type>, "Invalid type"); if constexpr(!std::is_void_v) { - const Type *instance = (in_situ && from.mode == policy::OWNED) + const Type *instance = (in_situ && from.mode == policy::OWNER) ? ENTT_LAUNDER(reinterpret_cast(&from.storage)) : static_cast(from.instance); @@ -72,14 +72,14 @@ class basic_any { break; case operation::MOVE: if constexpr(in_situ) { - if(from.mode == policy::OWNED) { + if(from.mode == policy::OWNER) { return new (&static_cast(to)->storage) Type{std::move(*const_cast(instance))}; } } return (static_cast(to)->instance = std::exchange(const_cast(from).instance, nullptr)); case operation::DTOR: - if(from.mode == policy::OWNED) { + if(from.mode == policy::OWNER) { if constexpr(in_situ) { instance->~Type(); } else if constexpr(std::is_array_v) { @@ -145,7 +145,7 @@ public: basic_any() ENTT_NOEXCEPT : instance{}, vtable{&basic_vtable}, - mode{policy::OWNED} + mode{policy::OWNER} {} /** @@ -185,7 +185,7 @@ public: basic_any(Type &&value) : instance{}, vtable{&basic_vtable>}, - mode{policy::OWNED} + mode{policy::OWNER} { initialize>(std::forward(value)); } @@ -197,7 +197,7 @@ public: basic_any(const basic_any &other) : instance{}, vtable{&basic_vtable}, - mode{policy::OWNED} + mode{policy::OWNER} { other.vtable(operation::COPY, other, this); } @@ -307,7 +307,7 @@ public: /*! @brief Destroys contained object */ void reset() { std::exchange(vtable, &basic_vtable)(operation::DTOR, *this, nullptr); - mode = policy::OWNED; + mode = policy::OWNER; } /** @@ -341,6 +341,14 @@ public: return basic_any{*this, policy::CREF}; } + /** + * @brief Returns true if a wrapper owns its object, false otherwise. + * @return True if the wrapper owns its object, false otherwise. + */ + [[nodiscard]] bool owner() const ENTT_NOEXCEPT { + return (mode == policy::OWNER); + } + private: union { const void *instance; storage_type storage; }; vtable_type *vtable; diff --git a/test/entt/core/any.cpp b/test/entt/core/any.cpp index fd2b93148..ab0663573 100644 --- a/test/entt/core/any.cpp +++ b/test/entt/core/any.cpp @@ -52,6 +52,7 @@ TEST_F(Any, SBO) { entt::any any{'c'}; ASSERT_TRUE(any); + ASSERT_TRUE(any.owner()); ASSERT_EQ(any.type(), entt::type_id()); ASSERT_EQ(entt::any_cast(&any), nullptr); ASSERT_EQ(entt::any_cast(any), 'c'); @@ -62,6 +63,7 @@ TEST_F(Any, NoSBO) { entt::any any{instance}; ASSERT_TRUE(any); + ASSERT_TRUE(any.owner()); ASSERT_EQ(any.type(), entt::type_id()); ASSERT_EQ(entt::any_cast(&any), nullptr); ASSERT_EQ(entt::any_cast(any), instance); @@ -71,6 +73,7 @@ TEST_F(Any, Empty) { entt::any any{}; ASSERT_FALSE(any); + ASSERT_TRUE(any.owner()); ASSERT_FALSE(any.type()); ASSERT_EQ(entt::any_cast(&any), nullptr); ASSERT_EQ(any.data(), nullptr); @@ -80,6 +83,7 @@ TEST_F(Any, SBOInPlaceTypeConstruction) { entt::any any{std::in_place_type, 42}; ASSERT_TRUE(any); + ASSERT_TRUE(any.owner()); ASSERT_EQ(any.type(), entt::type_id()); ASSERT_EQ(entt::any_cast(&any), nullptr); ASSERT_EQ(entt::any_cast(any), 42); @@ -87,6 +91,7 @@ TEST_F(Any, SBOInPlaceTypeConstruction) { auto other = any.as_ref(); ASSERT_TRUE(other); + ASSERT_FALSE(other.owner()); ASSERT_EQ(other.type(), entt::type_id()); ASSERT_EQ(entt::any_cast(other), 42); ASSERT_EQ(other.data(), any.data()); @@ -97,6 +102,7 @@ TEST_F(Any, SBOAsRefConstruction) { entt::any any{entt::forward_as_any(value)}; ASSERT_TRUE(any); + ASSERT_FALSE(any.owner()); ASSERT_EQ(any.type(), entt::type_id()); ASSERT_EQ(entt::any_cast(&any), nullptr); @@ -114,12 +120,14 @@ TEST_F(Any, SBOAsRefConstruction) { any.emplace(value); ASSERT_TRUE(any); + ASSERT_FALSE(any.owner()); ASSERT_EQ(any.type(), entt::type_id()); ASSERT_EQ(entt::any_cast(&any), &value); auto other = any.as_ref(); ASSERT_TRUE(other); + ASSERT_FALSE(other.owner()); ASSERT_EQ(other.type(), entt::type_id()); ASSERT_EQ(entt::any_cast(other), 42); ASSERT_EQ(other.data(), any.data()); @@ -130,6 +138,7 @@ TEST_F(Any, SBOAsConstRefConstruction) { entt::any any{entt::forward_as_any(value)}; ASSERT_TRUE(any); + ASSERT_FALSE(any.owner()); ASSERT_EQ(any.type(), entt::type_id()); ASSERT_EQ(entt::any_cast(&any), nullptr); @@ -147,12 +156,14 @@ TEST_F(Any, SBOAsConstRefConstruction) { any.emplace(value); ASSERT_TRUE(any); + ASSERT_FALSE(any.owner()); ASSERT_EQ(any.type(), entt::type_id()); ASSERT_EQ(entt::any_cast(&any), &value); auto other = any.as_ref(); ASSERT_TRUE(other); + ASSERT_FALSE(other.owner()); ASSERT_EQ(other.type(), entt::type_id()); ASSERT_EQ(entt::any_cast(other), 42); ASSERT_EQ(other.data(), any.data()); @@ -164,6 +175,8 @@ TEST_F(Any, SBOCopyConstruction) { ASSERT_TRUE(any); ASSERT_TRUE(other); + ASSERT_TRUE(any.owner()); + ASSERT_TRUE(other.owner()); ASSERT_EQ(any.type(), entt::type_id()); ASSERT_EQ(other.type(), entt::type_id()); ASSERT_EQ(entt::any_cast(&other), nullptr); @@ -178,6 +191,8 @@ TEST_F(Any, SBOCopyAssignment) { ASSERT_TRUE(any); ASSERT_TRUE(other); + ASSERT_TRUE(any.owner()); + ASSERT_TRUE(other.owner()); ASSERT_EQ(any.type(), entt::type_id()); ASSERT_EQ(other.type(), entt::type_id()); ASSERT_EQ(entt::any_cast(&other), nullptr); @@ -190,6 +205,8 @@ TEST_F(Any, SBOMoveConstruction) { ASSERT_TRUE(any); ASSERT_TRUE(other); + ASSERT_TRUE(any.owner()); + ASSERT_TRUE(other.owner()); ASSERT_NE(any.data(), nullptr); ASSERT_EQ(any.type(), entt::type_id()); ASSERT_EQ(other.type(), entt::type_id()); @@ -205,6 +222,8 @@ TEST_F(Any, SBOMoveAssignment) { ASSERT_TRUE(any); ASSERT_TRUE(other); + ASSERT_TRUE(any.owner()); + ASSERT_TRUE(other.owner()); ASSERT_NE(any.data(), nullptr); ASSERT_EQ(any.type(), entt::type_id()); ASSERT_EQ(other.type(), entt::type_id()); @@ -217,6 +236,7 @@ TEST_F(Any, SBODirectAssignment) { any = 42; ASSERT_TRUE(any); + ASSERT_TRUE(any.owner()); ASSERT_EQ(any.type(), entt::type_id()); ASSERT_EQ(entt::any_cast(&any), nullptr); ASSERT_EQ(entt::any_cast(any), 42); @@ -227,6 +247,7 @@ TEST_F(Any, NoSBOInPlaceTypeConstruction) { entt::any any{std::in_place_type, instance}; ASSERT_TRUE(any); + ASSERT_TRUE(any.owner()); ASSERT_EQ(any.type(), entt::type_id()); ASSERT_EQ(entt::any_cast(&any), nullptr); ASSERT_EQ(entt::any_cast(any), instance); @@ -234,6 +255,7 @@ TEST_F(Any, NoSBOInPlaceTypeConstruction) { auto other = any.as_ref(); ASSERT_TRUE(other); + ASSERT_FALSE(other.owner()); ASSERT_EQ(other.type(), entt::type_id()); ASSERT_EQ(entt::any_cast(other), (fat{.1, .2, .3, .4})); ASSERT_EQ(other.data(), any.data()); @@ -244,6 +266,7 @@ TEST_F(Any, NoSBOAsRefConstruction) { entt::any any{entt::forward_as_any(instance)}; ASSERT_TRUE(any); + ASSERT_FALSE(any.owner()); ASSERT_EQ(any.type(), entt::type_id()); ASSERT_EQ(entt::any_cast(&any), nullptr); @@ -261,12 +284,14 @@ TEST_F(Any, NoSBOAsRefConstruction) { any.emplace(instance); ASSERT_TRUE(any); + ASSERT_FALSE(any.owner()); ASSERT_EQ(any.type(), entt::type_id()); ASSERT_EQ(entt::any_cast(&any), &instance); auto other = any.as_ref(); ASSERT_TRUE(other); + ASSERT_FALSE(other.owner()); ASSERT_EQ(other.type(), entt::type_id()); ASSERT_EQ(entt::any_cast(other), (fat{.1, .2, .3, .4})); ASSERT_EQ(other.data(), any.data()); @@ -277,6 +302,7 @@ TEST_F(Any, NoSBOAsConstRefConstruction) { entt::any any{entt::forward_as_any(instance)}; ASSERT_TRUE(any); + ASSERT_FALSE(any.owner()); ASSERT_EQ(any.type(), entt::type_id()); ASSERT_EQ(entt::any_cast(&any), nullptr); @@ -294,12 +320,14 @@ TEST_F(Any, NoSBOAsConstRefConstruction) { any.emplace(instance); ASSERT_TRUE(any); + ASSERT_FALSE(any.owner()); ASSERT_EQ(any.type(), entt::type_id()); ASSERT_EQ(entt::any_cast(&any), &instance); auto other = any.as_ref(); ASSERT_TRUE(other); + ASSERT_FALSE(other.owner()); ASSERT_EQ(other.type(), entt::type_id()); ASSERT_EQ(entt::any_cast(other), (fat{.1, .2, .3, .4})); ASSERT_EQ(other.data(), any.data()); @@ -312,6 +340,8 @@ TEST_F(Any, NoSBOCopyConstruction) { ASSERT_TRUE(any); ASSERT_TRUE(other); + ASSERT_TRUE(any.owner()); + ASSERT_TRUE(other.owner()); ASSERT_EQ(any.type(), entt::type_id()); ASSERT_EQ(other.type(), entt::type_id()); ASSERT_EQ(entt::any_cast(&other), nullptr); @@ -327,6 +357,8 @@ TEST_F(Any, NoSBOCopyAssignment) { ASSERT_TRUE(any); ASSERT_TRUE(other); + ASSERT_TRUE(any.owner()); + ASSERT_TRUE(other.owner()); ASSERT_EQ(any.type(), entt::type_id()); ASSERT_EQ(other.type(), entt::type_id()); ASSERT_EQ(entt::any_cast(&other), nullptr); @@ -340,6 +372,8 @@ TEST_F(Any, NoSBOMoveConstruction) { ASSERT_FALSE(any); ASSERT_TRUE(other); + ASSERT_TRUE(any.owner()); + ASSERT_TRUE(other.owner()); ASSERT_EQ(any.data(), nullptr); ASSERT_EQ(any.type(), entt::type_id()); ASSERT_EQ(other.type(), entt::type_id()); @@ -356,6 +390,8 @@ TEST_F(Any, NoSBOMoveAssignment) { ASSERT_FALSE(any); ASSERT_TRUE(other); + ASSERT_TRUE(any.owner()); + ASSERT_TRUE(other.owner()); ASSERT_EQ(any.data(), nullptr); ASSERT_EQ(any.type(), entt::type_id()); ASSERT_EQ(other.type(), entt::type_id()); @@ -369,6 +405,7 @@ TEST_F(Any, NoSBODirectAssignment) { any = instance; ASSERT_TRUE(any); + ASSERT_TRUE(any.owner()); ASSERT_EQ(any.type(), entt::type_id()); ASSERT_EQ(entt::any_cast(&any), nullptr); ASSERT_EQ(entt::any_cast(any), instance); @@ -378,6 +415,7 @@ TEST_F(Any, VoidInPlaceTypeConstruction) { entt::any any{std::in_place_type}; ASSERT_FALSE(any); + ASSERT_TRUE(any.owner()); ASSERT_FALSE(any.type()); ASSERT_EQ(entt::any_cast(&any), nullptr); } @@ -388,6 +426,8 @@ TEST_F(Any, VoidCopyConstruction) { ASSERT_FALSE(any); ASSERT_FALSE(other); + ASSERT_TRUE(any.owner()); + ASSERT_TRUE(other.owner()); ASSERT_FALSE(any.type()); ASSERT_FALSE(other.type()); ASSERT_EQ(entt::any_cast(&any), nullptr); @@ -402,6 +442,8 @@ TEST_F(Any, VoidCopyAssignment) { ASSERT_FALSE(any); ASSERT_FALSE(other); + ASSERT_TRUE(any.owner()); + ASSERT_TRUE(other.owner()); ASSERT_FALSE(any.type()); ASSERT_FALSE(other.type()); ASSERT_EQ(entt::any_cast(&any), nullptr); @@ -414,6 +456,8 @@ TEST_F(Any, VoidMoveConstruction) { ASSERT_FALSE(any); ASSERT_FALSE(other); + ASSERT_TRUE(any.owner()); + ASSERT_TRUE(other.owner()); ASSERT_FALSE(any.type()); ASSERT_FALSE(other.type()); ASSERT_EQ(entt::any_cast(&any), nullptr); @@ -428,6 +472,8 @@ TEST_F(Any, VoidMoveAssignment) { ASSERT_FALSE(any); ASSERT_FALSE(other); + ASSERT_TRUE(any.owner()); + ASSERT_TRUE(other.owner()); ASSERT_FALSE(any.type()); ASSERT_FALSE(other.type()); ASSERT_EQ(entt::any_cast(&any), nullptr); @@ -499,6 +545,7 @@ TEST_F(Any, Emplace) { any.emplace(42); ASSERT_TRUE(any); + ASSERT_TRUE(any.owner()); ASSERT_EQ(any.type(), entt::type_id()); ASSERT_EQ(entt::any_cast(&any), nullptr); ASSERT_EQ(entt::any_cast(any), 42); @@ -509,6 +556,7 @@ TEST_F(Any, EmplaceVoid) { any.emplace(); ASSERT_FALSE(any); + ASSERT_TRUE(any.owner()); ASSERT_FALSE(any.type()); } @@ -516,11 +564,26 @@ TEST_F(Any, Reset) { entt::any any{42}; ASSERT_TRUE(any); + ASSERT_TRUE(any.owner()); ASSERT_EQ(any.type(), entt::type_id()); any.reset(); ASSERT_FALSE(any); + ASSERT_TRUE(any.owner()); + ASSERT_EQ(any.type(), entt::type_info{}); + + int value = 42; + any.emplace(value); + + ASSERT_TRUE(any); + ASSERT_FALSE(any.owner()); + ASSERT_EQ(any.type(), entt::type_id()); + + any.reset(); + + ASSERT_FALSE(any); + ASSERT_TRUE(any.owner()); ASSERT_EQ(any.type(), entt::type_info{}); } @@ -530,6 +593,9 @@ TEST_F(Any, SBOSwap) { std::swap(lhs, rhs); + ASSERT_TRUE(lhs.owner()); + ASSERT_TRUE(rhs.owner()); + ASSERT_EQ(lhs.type(), entt::type_id()); ASSERT_EQ(rhs.type(), entt::type_id()); ASSERT_EQ(entt::any_cast(&lhs), nullptr); @@ -544,6 +610,9 @@ TEST_F(Any, NoSBOSwap) { std::swap(lhs, rhs); + ASSERT_TRUE(lhs.owner()); + ASSERT_TRUE(rhs.owner()); + ASSERT_EQ(entt::any_cast(lhs), (fat{.4, .3, .2, .1})); ASSERT_EQ(entt::any_cast(rhs), (fat{.1, .2, .3, .4})); } @@ -555,6 +624,9 @@ TEST_F(Any, VoidSwap) { std::swap(lhs, rhs); + ASSERT_TRUE(lhs.owner()); + ASSERT_TRUE(rhs.owner()); + ASSERT_EQ(pre, lhs.data()); } @@ -564,6 +636,9 @@ TEST_F(Any, SBOWithNoSBOSwap) { std::swap(lhs, rhs); + ASSERT_TRUE(lhs.owner()); + ASSERT_TRUE(rhs.owner()); + ASSERT_EQ(lhs.type(), entt::type_id()); ASSERT_EQ(rhs.type(), entt::type_id()); ASSERT_EQ(entt::any_cast(&lhs), nullptr); @@ -579,6 +654,9 @@ TEST_F(Any, SBOWithRefSwap) { std::swap(lhs, rhs); + ASSERT_TRUE(lhs.owner()); + ASSERT_FALSE(rhs.owner()); + ASSERT_EQ(lhs.type(), entt::type_id()); ASSERT_EQ(rhs.type(), entt::type_id()); ASSERT_EQ(entt::any_cast(&lhs), nullptr); @@ -595,6 +673,9 @@ TEST_F(Any, SBOWithConstRefSwap) { std::swap(lhs, rhs); + ASSERT_TRUE(lhs.owner()); + ASSERT_FALSE(rhs.owner()); + ASSERT_EQ(lhs.type(), entt::type_id()); ASSERT_EQ(rhs.type(), entt::type_id()); ASSERT_EQ(entt::any_cast(&lhs), nullptr); @@ -612,6 +693,7 @@ TEST_F(Any, SBOWithEmptySwap) { std::swap(lhs, rhs); ASSERT_FALSE(lhs); + ASSERT_TRUE(lhs.owner()); ASSERT_EQ(rhs.type(), entt::type_id()); ASSERT_EQ(entt::any_cast(&lhs), nullptr); ASSERT_EQ(entt::any_cast(&rhs), nullptr); @@ -620,6 +702,7 @@ TEST_F(Any, SBOWithEmptySwap) { std::swap(lhs, rhs); ASSERT_FALSE(rhs); + ASSERT_TRUE(rhs.owner()); ASSERT_EQ(lhs.type(), entt::type_id()); ASSERT_EQ(entt::any_cast(&lhs), nullptr); ASSERT_EQ(entt::any_cast(&rhs), nullptr); @@ -633,6 +716,7 @@ TEST_F(Any, SBOWithVoidSwap) { std::swap(lhs, rhs); ASSERT_FALSE(lhs); + ASSERT_TRUE(lhs.owner()); ASSERT_EQ(rhs.type(), entt::type_id()); ASSERT_EQ(entt::any_cast(&lhs), nullptr); ASSERT_EQ(entt::any_cast(&rhs), nullptr); @@ -641,6 +725,7 @@ TEST_F(Any, SBOWithVoidSwap) { std::swap(lhs, rhs); ASSERT_FALSE(rhs); + ASSERT_TRUE(rhs.owner()); ASSERT_EQ(lhs.type(), entt::type_id()); ASSERT_EQ(entt::any_cast(&lhs), nullptr); ASSERT_EQ(entt::any_cast(&rhs), nullptr); @@ -654,6 +739,9 @@ TEST_F(Any, NoSBOWithRefSwap) { std::swap(lhs, rhs); + ASSERT_TRUE(lhs.owner()); + ASSERT_FALSE(rhs.owner()); + ASSERT_EQ(lhs.type(), entt::type_id()); ASSERT_EQ(rhs.type(), entt::type_id()); ASSERT_EQ(entt::any_cast(&lhs), nullptr); @@ -670,6 +758,9 @@ TEST_F(Any, NoSBOWithConstRefSwap) { std::swap(lhs, rhs); + ASSERT_TRUE(lhs.owner()); + ASSERT_FALSE(rhs.owner()); + ASSERT_EQ(lhs.type(), entt::type_id()); ASSERT_EQ(rhs.type(), entt::type_id()); ASSERT_EQ(entt::any_cast(&lhs), nullptr); @@ -687,6 +778,7 @@ TEST_F(Any, NoSBOWithEmptySwap) { std::swap(lhs, rhs); ASSERT_FALSE(lhs); + ASSERT_TRUE(lhs.owner()); ASSERT_EQ(rhs.type(), entt::type_id()); ASSERT_EQ(entt::any_cast(&lhs), nullptr); ASSERT_EQ(entt::any_cast(&rhs), nullptr); @@ -695,6 +787,7 @@ TEST_F(Any, NoSBOWithEmptySwap) { std::swap(lhs, rhs); ASSERT_FALSE(rhs); + ASSERT_TRUE(rhs.owner()); ASSERT_EQ(lhs.type(), entt::type_id()); ASSERT_EQ(entt::any_cast(&lhs), nullptr); ASSERT_EQ(entt::any_cast(&rhs), nullptr); @@ -708,6 +801,7 @@ TEST_F(Any, NoSBOWithVoidSwap) { std::swap(lhs, rhs); ASSERT_FALSE(lhs); + ASSERT_TRUE(lhs.owner()); ASSERT_EQ(rhs.type(), entt::type_id()); ASSERT_EQ(entt::any_cast(&lhs), nullptr); ASSERT_EQ(entt::any_cast(&rhs), nullptr); @@ -716,6 +810,7 @@ TEST_F(Any, NoSBOWithVoidSwap) { std::swap(lhs, rhs); ASSERT_FALSE(rhs); + ASSERT_TRUE(rhs.owner()); ASSERT_EQ(lhs.type(), entt::type_id()); ASSERT_EQ(entt::any_cast(&lhs), nullptr); ASSERT_EQ(entt::any_cast(&rhs), nullptr); @@ -727,6 +822,9 @@ TEST_F(Any, AsRef) { auto ref = any.as_ref(); auto cref = std::as_const(any).as_ref(); + ASSERT_FALSE(ref.owner()); + ASSERT_FALSE(cref.owner()); + ASSERT_EQ(entt::any_cast(&any), any.data()); ASSERT_EQ(entt::any_cast(&ref), any.data()); ASSERT_EQ(entt::any_cast(&cref), nullptr); @@ -758,12 +856,18 @@ TEST_F(Any, AsRef) { std::swap(ref, cref); + ASSERT_FALSE(ref.owner()); + ASSERT_FALSE(cref.owner()); + ASSERT_EQ(entt::any_cast(&ref), nullptr); ASSERT_EQ(entt::any_cast(&cref), any.data()); ref = ref.as_ref(); cref = std::as_const(cref).as_ref(); + ASSERT_FALSE(ref.owner()); + ASSERT_FALSE(cref.owner()); + ASSERT_EQ(entt::any_cast(&ref), nullptr); ASSERT_EQ(entt::any_cast(&cref), nullptr); ASSERT_EQ(entt::any_cast(&ref), any.data()); @@ -778,6 +882,9 @@ TEST_F(Any, AsRef) { ref = 42; cref = 42; + ASSERT_TRUE(ref.owner()); + ASSERT_TRUE(cref.owner()); + ASSERT_NE(entt::any_cast(&ref), nullptr); ASSERT_NE(entt::any_cast(&cref), nullptr); ASSERT_EQ(entt::any_cast(ref), 42); @@ -867,6 +974,10 @@ TEST_F(Any, MakeAny) { ASSERT_TRUE(ext); ASSERT_TRUE(ref); + ASSERT_TRUE(any.owner()); + ASSERT_TRUE(ext.owner()); + ASSERT_FALSE(ref.owner()); + ASSERT_EQ(entt::any_cast(any), 42); ASSERT_EQ(entt::any_cast(ext), 42); ASSERT_EQ(entt::any_cast(ref), 42); @@ -890,6 +1001,10 @@ TEST_F(Any, ForwardAsAny) { ASSERT_TRUE(ref); ASSERT_TRUE(cref); + ASSERT_TRUE(any.owner()); + ASSERT_FALSE(ref.owner()); + ASSERT_FALSE(cref.owner()); + ASSERT_NE(entt::any_cast(&any), nullptr); ASSERT_NE(entt::any_cast(&ref), nullptr); ASSERT_EQ(entt::any_cast(&cref), nullptr); @@ -909,10 +1024,16 @@ TEST_F(Any, NotCopyableType) { ASSERT_TRUE(any); ASSERT_FALSE(copy); + ASSERT_TRUE(any.owner()); + ASSERT_TRUE(copy.owner()); + copy = any; ASSERT_TRUE(any); ASSERT_FALSE(copy); + + ASSERT_TRUE(any.owner()); + ASSERT_TRUE(copy.owner()); }; test(entt::any{std::in_place_type>}); @@ -950,6 +1071,10 @@ TEST_F(Any, CopyMoveReference) { ASSERT_TRUE(move); ASSERT_TRUE(copy); + ASSERT_FALSE(any.owner()); + ASSERT_FALSE(move.owner()); + ASSERT_TRUE(copy.owner()); + ASSERT_EQ(move.type(), entt::type_id()); ASSERT_EQ(copy.type(), entt::type_id());