diff --git a/src/entt/meta/meta.hpp b/src/entt/meta/meta.hpp index afb43b263..e6fb5a1e7 100644 --- a/src/entt/meta/meta.hpp +++ b/src/entt/meta/meta.hpp @@ -359,12 +359,12 @@ class meta_any { [[nodiscard]] inline meta_type type() const noexcept; /*! @copydoc any::data */ - [[nodiscard]] const void *data() const noexcept { + [[nodiscard]] [[deprecated("use ::base().data() instead")]] const void *data() const noexcept { return storage.data(); } /*! @copydoc any::data */ - [[nodiscard]] void *data() noexcept { + [[nodiscard]] [[deprecated("no longer supported, use ::base().data() for const access")]] void *data() noexcept { return storage.data(); } @@ -410,7 +410,7 @@ class meta_any { template [[nodiscard]] const Type *try_cast() const { const auto other = internal::resolve>(internal::meta_context::from(*ctx)); - return static_cast(internal::try_cast(internal::meta_context::from(*ctx), node, other, data())); + return static_cast(internal::try_cast(internal::meta_context::from(*ctx), node, other, storage.data())); } /*! @copydoc try_cast */ @@ -420,7 +420,7 @@ class meta_any { return std::as_const(*this).try_cast>(); } else { const auto other = internal::resolve>(internal::meta_context::from(*ctx)); - return static_cast(const_cast(internal::try_cast(internal::meta_context::from(*ctx), node, other, data()))); + return static_cast(const_cast(internal::try_cast(internal::meta_context::from(*ctx), node, other, storage.data()))); } } @@ -1522,7 +1522,7 @@ bool meta_any::set(const id_type id, Type &&value) { } [[nodiscard]] inline meta_any meta_any::allow_cast(const meta_type &type) const { - return internal::try_convert(internal::meta_context::from(*ctx), node, type.info(), type.is_arithmetic() || type.is_enum(), data(), [this, &type]([[maybe_unused]] const void *instance, auto &&...args) { + return internal::try_convert(internal::meta_context::from(*ctx), node, type.info(), type.is_arithmetic() || type.is_enum(), storage.data(), [this, &type]([[maybe_unused]] const void *instance, auto &&...args) { if constexpr((std::is_same_v>, internal::meta_type_node> || ...)) { return (args.from_void(*ctx, nullptr, instance), ...); } else if constexpr((std::is_same_v>, internal::meta_conv_node> || ...)) { @@ -1531,7 +1531,7 @@ bool meta_any::set(const id_type id, Type &&value) { // exploits the fact that arithmetic types and enums are also default constructible auto other = type.construct(); const auto value = (args(nullptr, instance), ...); - other.node.conversion_helper(other.data(), &value); + other.node.conversion_helper(other.storage.data(), &value); return other; } else { // forwards to force a compile-time error in case of available arguments @@ -1790,7 +1790,7 @@ inline meta_sequence_container::iterator meta_sequence_container::insert(const i // this abomination is necessary because only on macos value_type and const_reference are different types for std::vector if(const auto vtype = value_type_node(internal::meta_context::from(*ctx)); !const_only && (value.allow_cast({*ctx, vtype}) || value.allow_cast({*ctx, const_reference_node(internal::meta_context::from(*ctx))}))) { const bool is_value_type = (value.type().info() == *vtype.info); - return insert_fn(*ctx, const_cast(data), is_value_type ? std::as_const(value).data() : nullptr, is_value_type ? nullptr : std::as_const(value).data(), it); + return insert_fn(*ctx, const_cast(data), is_value_type ? value.base().data() : nullptr, is_value_type ? nullptr : value.base().data(), it); } return iterator{}; @@ -1879,7 +1879,7 @@ inline bool meta_associative_container::reserve(const size_type sz) { inline bool meta_associative_container::insert(meta_any key, meta_any value = {}) { return !const_only && key.allow_cast(meta_type{*ctx, key_type_node(internal::meta_context::from(*ctx))}) && ((mapped_type_node == nullptr) || value.allow_cast(meta_type{*ctx, mapped_type_node(internal::meta_context::from(*ctx))})) - && insert_fn(const_cast(data), std::as_const(key).data(), std::as_const(value).data()); + && insert_fn(const_cast(data), key.base().data(), value.base().data()); } /** @@ -1888,7 +1888,7 @@ inline bool meta_associative_container::insert(meta_any key, meta_any value = {} * @return A bool denoting whether the removal took place. */ inline meta_associative_container::size_type meta_associative_container::erase(meta_any key) { - return (!const_only && key.allow_cast(meta_type{*ctx, key_type_node(internal::meta_context::from(*ctx))})) ? erase_fn(const_cast(data), std::as_const(key).data()) : 0u; + return (!const_only && key.allow_cast(meta_type{*ctx, key_type_node(internal::meta_context::from(*ctx))})) ? erase_fn(const_cast(data), key.base().data()) : 0u; } /** @@ -1897,7 +1897,7 @@ inline meta_associative_container::size_type meta_associative_container::erase(m * @return An iterator to the element with the given key, if any. */ [[nodiscard]] inline meta_associative_container::iterator meta_associative_container::find(meta_any key) { - return key.allow_cast(meta_type{*ctx, key_type_node(internal::meta_context::from(*ctx))}) ? find_fn(*ctx, const_only ? nullptr : const_cast(data), data, std::as_const(key).data()) : iterator{}; + return key.allow_cast(meta_type{*ctx, key_type_node(internal::meta_context::from(*ctx))}) ? find_fn(*ctx, const_only ? nullptr : const_cast(data), data, key.base().data()) : iterator{}; } /** diff --git a/test/entt/meta/meta_any.cpp b/test/entt/meta/meta_any.cpp index e22f560f8..0e0e2af32 100644 --- a/test/entt/meta/meta_any.cpp +++ b/test/entt/meta/meta_any.cpp @@ -149,7 +149,7 @@ TEST_F(MetaAny, Empty) { ASSERT_FALSE(any); ASSERT_FALSE(any.type()); ASSERT_FALSE(any.try_cast()); - ASSERT_EQ(any.data(), nullptr); + ASSERT_EQ(any.base().data(), nullptr); ASSERT_EQ(any, entt::meta_any{}); ASSERT_NE(entt::meta_any{'c'}, any); @@ -168,7 +168,7 @@ TEST_F(MetaAny, SBOInPlaceTypeConstruction) { ASSERT_TRUE(any); ASSERT_FALSE(any.try_cast()); ASSERT_EQ(any.cast(), 3); - ASSERT_NE(any.data(), nullptr); + ASSERT_NE(any.base().data(), nullptr); ASSERT_EQ(any, (entt::meta_any{std::in_place_type, 3})); ASSERT_EQ(any, entt::meta_any{3}); ASSERT_NE(entt::meta_any{1}, any); @@ -188,8 +188,7 @@ TEST_F(MetaAny, SBOAsRefConstruction) { ASSERT_EQ(any.cast(), 1); ASSERT_EQ(any.cast(), 1); ASSERT_EQ(any.cast(), 1); - ASSERT_EQ(any.data(), &value); - ASSERT_EQ(std::as_const(any).data(), &value); + ASSERT_EQ(any.base().data(), &value); ASSERT_EQ(any, entt::forward_as_meta(value)); ASSERT_NE(any, entt::forward_as_meta(compare)); @@ -201,14 +200,14 @@ TEST_F(MetaAny, SBOAsRefConstruction) { ASSERT_TRUE(any); ASSERT_EQ(any.type(), entt::resolve()); - ASSERT_EQ(std::as_const(any).data(), &value); + ASSERT_EQ(any.base().data(), &value); auto other = any.as_ref(); ASSERT_TRUE(other); ASSERT_EQ(any.type(), entt::resolve()); ASSERT_EQ(any.cast(), 1); - ASSERT_EQ(other.data(), any.data()); + ASSERT_EQ(other.base().data(), any.base().data()); } TEST_F(MetaAny, SBOAsConstRefConstruction) { @@ -224,8 +223,7 @@ TEST_F(MetaAny, SBOAsConstRefConstruction) { ASSERT_FALSE(any.try_cast()); ASSERT_EQ(any.cast(), 1); ASSERT_EQ(any.cast(), 1); - ASSERT_EQ(any.data(), nullptr); - ASSERT_EQ(std::as_const(any).data(), &value); + ASSERT_EQ(any.base().data(), &value); ASSERT_EQ(any, entt::forward_as_meta(value)); ASSERT_NE(any, entt::forward_as_meta(compare)); @@ -237,14 +235,14 @@ TEST_F(MetaAny, SBOAsConstRefConstruction) { ASSERT_TRUE(any); ASSERT_EQ(any.type(), entt::resolve()); - ASSERT_EQ(std::as_const(any).data(), &value); + ASSERT_EQ(any.base().data(), &value); auto other = any.as_ref(); ASSERT_TRUE(other); ASSERT_EQ(any.type(), entt::resolve()); ASSERT_EQ(any.cast(), 1); - ASSERT_EQ(other.data(), any.data()); + ASSERT_EQ(other.base().data(), any.base().data()); } ENTT_DEBUG_TEST_F(MetaAnyDeathTest, SBOAsConstRefConstruction) { @@ -462,7 +460,7 @@ TEST_F(MetaAny, NoSBOInPlaceTypeConstruction) { ASSERT_TRUE(any); ASSERT_FALSE(any.try_cast()); ASSERT_EQ(any.cast(), instance); - ASSERT_NE(any.data(), nullptr); + ASSERT_NE(any.base().data(), nullptr); ASSERT_EQ(any, (entt::meta_any{std::in_place_type, instance})); ASSERT_EQ(any, entt::meta_any{instance}); ASSERT_NE(entt::meta_any{fat{}}, any); @@ -481,8 +479,7 @@ TEST_F(MetaAny, NoSBOAsRefConstruction) { ASSERT_EQ(any.cast(), instance); ASSERT_EQ(any.cast(), instance); ASSERT_EQ(any.cast(), instance); - ASSERT_EQ(any.data(), &instance); - ASSERT_EQ(std::as_const(any).data(), &instance); + ASSERT_EQ(any.base().data(), &instance); ASSERT_EQ(any, entt::forward_as_meta(instance)); @@ -493,14 +490,14 @@ TEST_F(MetaAny, NoSBOAsRefConstruction) { ASSERT_TRUE(any); ASSERT_EQ(any.type(), entt::resolve()); - ASSERT_EQ(std::as_const(any).data(), &instance); + ASSERT_EQ(any.base().data(), &instance); auto other = any.as_ref(); ASSERT_TRUE(other); ASSERT_EQ(any.type(), entt::resolve()); ASSERT_EQ(any, entt::meta_any{instance}); - ASSERT_EQ(other.data(), any.data()); + ASSERT_EQ(other.base().data(), any.base().data()); } TEST_F(MetaAny, NoSBOAsConstRefConstruction) { @@ -515,8 +512,7 @@ TEST_F(MetaAny, NoSBOAsConstRefConstruction) { ASSERT_FALSE(any.try_cast()); ASSERT_EQ(any.cast(), instance); ASSERT_EQ(any.cast(), instance); - ASSERT_EQ(any.data(), nullptr); - ASSERT_EQ(std::as_const(any).data(), &instance); + ASSERT_EQ(any.base().data(), &instance); ASSERT_EQ(any, entt::forward_as_meta(instance)); @@ -527,14 +523,14 @@ TEST_F(MetaAny, NoSBOAsConstRefConstruction) { ASSERT_TRUE(any); ASSERT_EQ(any.type(), entt::resolve()); - ASSERT_EQ(std::as_const(any).data(), &instance); + ASSERT_EQ(any.base().data(), &instance); auto other = any.as_ref(); ASSERT_TRUE(other); ASSERT_EQ(any.type(), entt::resolve()); ASSERT_EQ(any, entt::meta_any{instance}); - ASSERT_EQ(other.data(), any.data()); + ASSERT_EQ(other.base().data(), any.base().data()); } ENTT_DEBUG_TEST_F(MetaAnyDeathTest, NoSBOAsConstRefConstruction) { @@ -642,7 +638,7 @@ TEST_F(MetaAny, NoSBOAssignValue) { const entt::meta_any other{fat{.0, .1, .2, .3}}; const entt::meta_any invalid{'c'}; - const void *addr = std::as_const(any).data(); + const void *addr = any.base().data(); ASSERT_TRUE(any); ASSERT_EQ(any.cast(), (fat{.1, .2, .3, .4})); @@ -650,7 +646,7 @@ TEST_F(MetaAny, NoSBOAssignValue) { ASSERT_TRUE(any.assign(other)); ASSERT_FALSE(any.assign(invalid)); ASSERT_EQ(any.cast(), (fat{.0, .1, .2, .3})); - ASSERT_EQ(addr, std::as_const(any).data()); + ASSERT_EQ(addr, any.base().data()); } TEST_F(MetaAny, NoSBOConvertAssignValue) { @@ -658,12 +654,12 @@ TEST_F(MetaAny, NoSBOConvertAssignValue) { const entt::meta_any other{fat{.0, .1, .2, .3}}; const entt::meta_any invalid{'c'}; - const void *addr = std::as_const(any).data(); + const void *addr = any.base().data(); ASSERT_TRUE(any); ASSERT_TRUE(any.assign(other)); ASSERT_FALSE(any.assign(invalid)); - ASSERT_EQ(addr, std::as_const(any).data()); + ASSERT_EQ(addr, any.base().data()); } TEST_F(MetaAny, NoSBOAsRefAssignValue) { @@ -699,7 +695,7 @@ TEST_F(MetaAny, NoSBOAsConstRefAssignValue) { TEST_F(MetaAny, NoSBOTransferValue) { entt::meta_any any{fat{.1, .2, .3, .4}}; - const void *addr = std::as_const(any).data(); + const void *addr = any.base().data(); ASSERT_TRUE(any); ASSERT_EQ(any.cast(), (fat{.1, .2, .3, .4})); @@ -707,39 +703,39 @@ TEST_F(MetaAny, NoSBOTransferValue) { ASSERT_TRUE(any.assign(fat{.0, .1, .2, .3})); ASSERT_FALSE(any.assign('c')); ASSERT_EQ(any.cast(), (fat{.0, .1, .2, .3})); - ASSERT_EQ(addr, std::as_const(any).data()); + ASSERT_EQ(addr, any.base().data()); } TEST_F(MetaAny, NoSBOTransferConstValue) { const fat instance{.0, .1, .2, .3}; entt::meta_any any{fat{.1, .2, .3, .4}}; - const void *addr = std::as_const(any).data(); + const void *addr = any.base().data(); ASSERT_TRUE(any); ASSERT_EQ(any.cast(), (fat{.1, .2, .3, .4})); ASSERT_TRUE(any.assign(entt::forward_as_meta(instance))); ASSERT_EQ(any.cast(), (fat{.0, .1, .2, .3})); - ASSERT_EQ(addr, std::as_const(any).data()); + ASSERT_EQ(addr, any.base().data()); } TEST_F(MetaAny, NoSBOConvertTransferValue) { entt::meta_any any{empty{}}; - const void *addr = std::as_const(any).data(); + const void *addr = any.base().data(); ASSERT_TRUE(any); ASSERT_TRUE(any.assign(fat{.0, .1, .2, .3})); ASSERT_FALSE(any.assign('c')); - ASSERT_EQ(addr, std::as_const(any).data()); + ASSERT_EQ(addr, any.base().data()); } TEST_F(MetaAny, NoSBOAsRefTransferValue) { fat instance{.1, .2, .3, .4}; entt::meta_any any{entt::forward_as_meta(instance)}; - const void *addr = std::as_const(any).data(); + const void *addr = any.base().data(); ASSERT_TRUE(any); ASSERT_EQ(any.cast(), (fat{.1, .2, .3, .4})); @@ -748,14 +744,14 @@ TEST_F(MetaAny, NoSBOAsRefTransferValue) { ASSERT_FALSE(any.assign('c')); ASSERT_EQ(any.cast(), (fat{.0, .1, .2, .3})); ASSERT_EQ(instance, (fat{.0, .1, .2, .3})); - ASSERT_EQ(addr, std::as_const(any).data()); + ASSERT_EQ(addr, any.base().data()); } TEST_F(MetaAny, NoSBOAsConstRefTransferValue) { const fat instance{.1, .2, .3, .4}; entt::meta_any any{entt::forward_as_meta(instance)}; - const void *addr = std::as_const(any).data(); + const void *addr = any.base().data(); ASSERT_TRUE(any); ASSERT_EQ(any.cast(), (fat{.1, .2, .3, .4})); @@ -764,7 +760,7 @@ TEST_F(MetaAny, NoSBOAsConstRefTransferValue) { ASSERT_FALSE(any.assign('c')); ASSERT_EQ(any.cast(), (fat{.1, .2, .3, .4})); ASSERT_EQ(instance, (fat{.1, .2, .3, .4})); - ASSERT_EQ(addr, std::as_const(any).data()); + ASSERT_EQ(addr, any.base().data()); } TEST_F(MetaAny, VoidInPlaceTypeConstruction) { @@ -774,7 +770,7 @@ TEST_F(MetaAny, VoidInPlaceTypeConstruction) { ASSERT_FALSE(any.base().owner()); ASSERT_EQ(any.base().policy(), entt::any_policy::empty); ASSERT_FALSE(any.try_cast()); - ASSERT_EQ(any.data(), nullptr); + ASSERT_EQ(any.base().data(), nullptr); ASSERT_EQ(any.type(), entt::resolve()); ASSERT_EQ(any, entt::meta_any{std::in_place_type}); ASSERT_NE(entt::meta_any{3}, any); @@ -926,7 +922,7 @@ TEST_F(MetaAny, Emplace) { ASSERT_TRUE(any); ASSERT_FALSE(any.try_cast()); ASSERT_EQ(any.cast(), 3); - ASSERT_NE(any.data(), nullptr); + ASSERT_NE(any.base().data(), nullptr); ASSERT_EQ(any, (entt::meta_any{std::in_place_type, 3})); ASSERT_EQ(any, entt::meta_any{3}); ASSERT_NE(entt::meta_any{1}, any); @@ -937,7 +933,7 @@ TEST_F(MetaAny, EmplaceVoid) { any.emplace(); ASSERT_TRUE(any); - ASSERT_EQ(any.data(), nullptr); + ASSERT_EQ(any.base().data(), nullptr); ASSERT_EQ(any.type(), entt::resolve()); ASSERT_EQ(any, (entt::meta_any{std::in_place_type})); } @@ -979,11 +975,11 @@ TEST_F(MetaAny, NoSBOSwap) { TEST_F(MetaAny, VoidSwap) { entt::meta_any lhs{std::in_place_type}; entt::meta_any rhs{std::in_place_type}; - const auto *pre = lhs.data(); + const auto *pre = lhs.base().data(); std::swap(lhs, rhs); - ASSERT_EQ(pre, lhs.data()); + ASSERT_EQ(pre, lhs.base().data()); } TEST_F(MetaAny, SBOWithNoSBOSwap) { @@ -1058,13 +1054,13 @@ TEST_F(MetaAny, AsRef) { auto ref = any.as_ref(); auto cref = std::as_const(any).as_ref(); - ASSERT_EQ(any.try_cast(), any.data()); - ASSERT_EQ(ref.try_cast(), any.data()); + ASSERT_EQ(any.try_cast(), any.base().data()); + ASSERT_EQ(ref.try_cast(), any.base().data()); ASSERT_EQ(cref.try_cast(), nullptr); - ASSERT_EQ(any.try_cast(), any.data()); - ASSERT_EQ(ref.try_cast(), any.data()); - ASSERT_EQ(cref.try_cast(), any.data()); + ASSERT_EQ(any.try_cast(), any.base().data()); + ASSERT_EQ(ref.try_cast(), any.base().data()); + ASSERT_EQ(cref.try_cast(), any.base().data()); ASSERT_EQ(any.cast(), 3); ASSERT_EQ(ref.cast(), 3); @@ -1089,15 +1085,15 @@ TEST_F(MetaAny, AsRef) { std::swap(ref, cref); ASSERT_EQ(ref.try_cast(), nullptr); - ASSERT_EQ(cref.try_cast(), any.data()); + ASSERT_EQ(cref.try_cast(), any.base().data()); ref = ref.as_ref(); cref = std::as_const(cref).as_ref(); ASSERT_EQ(ref.try_cast(), nullptr); ASSERT_EQ(cref.try_cast(), nullptr); - ASSERT_EQ(ref.try_cast(), any.data()); - ASSERT_EQ(cref.try_cast(), any.data()); + ASSERT_EQ(ref.try_cast(), any.base().data()); + ASSERT_EQ(cref.try_cast(), any.base().data()); ASSERT_EQ(ref.cast(), 1); ASSERT_EQ(cref.cast(), 1); @@ -1111,8 +1107,8 @@ TEST_F(MetaAny, AsRef) { ASSERT_EQ(cref.cast(), 3); ASSERT_EQ(ref.cast(), 3); ASSERT_EQ(cref.cast(), 3); - ASSERT_NE(ref.try_cast(), any.data()); - ASSERT_NE(cref.try_cast(), any.data()); + ASSERT_NE(ref.try_cast(), any.base().data()); + ASSERT_NE(cref.try_cast(), any.base().data()); any.emplace(); ref = any.as_ref(); @@ -1180,9 +1176,9 @@ TEST_F(MetaAny, TryCast) { ASSERT_EQ(any.type(), entt::resolve()); ASSERT_EQ(any.try_cast(), nullptr); ASSERT_NE(any.try_cast(), nullptr); - ASSERT_EQ(any.try_cast(), any.data()); + ASSERT_EQ(any.try_cast(), any.base().data()); ASSERT_EQ(std::as_const(any).try_cast(), any.try_cast()); - ASSERT_EQ(std::as_const(any).try_cast(), any.data()); + ASSERT_EQ(std::as_const(any).try_cast(), any.base().data()); ASSERT_EQ(std::as_const(any).try_cast(), nullptr); } @@ -1399,7 +1395,7 @@ TEST_F(MetaAny, UnmanageableType) { ASSERT_TRUE(other); ASSERT_EQ(any.type(), entt::resolve()); - ASSERT_NE(any.data(), nullptr); + ASSERT_NE(any.base().data(), nullptr); ASSERT_EQ(any.try_cast(), nullptr); ASSERT_NE(any.try_cast(), nullptr); @@ -1467,6 +1463,6 @@ TEST_F(MetaAny, ForwardAsMeta) { ASSERT_EQ(ref.cast(), 3); ASSERT_EQ(cref.cast(), 3); - ASSERT_NE(any.data(), &value); - ASSERT_EQ(ref.data(), &value); + ASSERT_NE(any.base().data(), &value); + ASSERT_EQ(ref.base().data(), &value); }