From 11e6b65108bd4797da41dc03d48237f693fcaa11 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Tue, 30 Jul 2024 08:49:30 +0200 Subject: [PATCH] meta: non-const access to meta custom --- TODO | 1 - src/entt/meta/meta.hpp | 4 ++-- test/entt/meta/meta_custom.cpp | 11 +++++++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/TODO b/TODO index 09d5d0cf0..c35c49cbe 100644 --- a/TODO +++ b/TODO @@ -45,4 +45,3 @@ TODO: * natvis for meta_custom * meta: vectors for details and props * suppress -Wself-move on CI with g++13 -* meta_custom operator bool diff --git a/src/entt/meta/meta.hpp b/src/entt/meta/meta.hpp index ecf07acb7..b7b120a47 100644 --- a/src/entt/meta/meta.hpp +++ b/src/entt/meta/meta.hpp @@ -843,7 +843,7 @@ struct meta_custom { * @tparam Type Type to which conversion is requested. */ template - [[nodiscard]] operator const Type *() const noexcept { + [[nodiscard]] operator Type *() const noexcept { return (type_id().hash() == node.type) ? std::static_pointer_cast(node.value).get() : nullptr; } @@ -852,7 +852,7 @@ struct meta_custom { * @tparam Type Type to which conversion is requested. */ template - [[nodiscard]] operator const Type &() const noexcept { + [[nodiscard]] operator Type &() const noexcept { ENTT_ASSERT(type_id().hash() == node.type, "Invalid type"); return *std::static_pointer_cast(node.value); } diff --git a/test/entt/meta/meta_custom.cpp b/test/entt/meta/meta_custom.cpp index 38dc363f9..d7b63e249 100644 --- a/test/entt/meta/meta_custom.cpp +++ b/test/entt/meta/meta_custom.cpp @@ -113,6 +113,17 @@ TEST_F(MetaCustom, Func) { ASSERT_EQ(static_cast(entt::resolve().func("g"_hs).custom()), nullptr); } +TEST_F(MetaCustom, ConstNonConstAndAllInBetween) { + testing::StaticAssertTypeEq(entt::meta_custom{})), int *>(); + testing::StaticAssertTypeEq(entt::meta_custom{})), int &>(); + testing::StaticAssertTypeEq(entt::meta_custom{})), const int *>(); + testing::StaticAssertTypeEq(entt::meta_custom{})), const int &>(); + + static_cast(entt::resolve().custom()) = '\n'; + + ASSERT_EQ(*static_cast(entt::resolve().custom()), '\n'); +} + TEST_F(MetaCustom, ReRegistration) { using namespace entt::literals;