From 178a4486cfb1efbee4c8dd3b43fb40612896f995 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Wed, 8 Feb 2023 06:22:45 +0700 Subject: [PATCH] return an empty type for empty uvalues --- develop/singles/headers/meta.hpp/meta_all.hpp | 7 +++---- develop/untests/meta_utilities/value_tests.cpp | 2 +- headers/meta.hpp/meta_uvalue.hpp | 2 +- headers/meta.hpp/meta_uvalue/uvalue.hpp | 5 ++--- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/develop/singles/headers/meta.hpp/meta_all.hpp b/develop/singles/headers/meta.hpp/meta_all.hpp index 041f825..4e166d1 100644 --- a/develop/singles/headers/meta.hpp/meta_all.hpp +++ b/develop/singles/headers/meta.hpp/meta_all.hpp @@ -2844,7 +2844,7 @@ namespace meta_hpp void reset(); void swap(uvalue& other) noexcept; - [[nodiscard]] const any_type& get_type() const noexcept; + [[nodiscard]] any_type get_type() const noexcept; [[nodiscard]] void* get_data() noexcept; [[nodiscard]] const void* get_data() const noexcept; @@ -8698,10 +8698,9 @@ namespace meta_hpp vtable_t::do_swap(*this, other); } - inline const any_type& uvalue::get_type() const noexcept { - static any_type void_type = resolve_type(); + inline any_type uvalue::get_type() const noexcept { auto&& [tag, vtable] = vtable_t::unpack_vtag(*this); - return tag == storage_e::nothing ? void_type : vtable->type; + return tag == storage_e::nothing ? any_type{} : vtable->type; } inline void* uvalue::get_data() noexcept { diff --git a/develop/untests/meta_utilities/value_tests.cpp b/develop/untests/meta_utilities/value_tests.cpp index 16dc13f..c174148 100644 --- a/develop/untests/meta_utilities/value_tests.cpp +++ b/develop/untests/meta_utilities/value_tests.cpp @@ -178,7 +178,7 @@ TEST_CASE("meta/meta_utilities/value") { CHECK_THROWS(std::ignore = std::move(std::as_const(val)).get_as()); } - CHECK(meta::uvalue{}.get_type() == meta::resolve_type()); + CHECK_FALSE(meta::uvalue{}.get_type()); } SUBCASE("ivec2&") { diff --git a/headers/meta.hpp/meta_uvalue.hpp b/headers/meta.hpp/meta_uvalue.hpp index 2a63264..52b627c 100644 --- a/headers/meta.hpp/meta_uvalue.hpp +++ b/headers/meta.hpp/meta_uvalue.hpp @@ -76,7 +76,7 @@ namespace meta_hpp void reset(); void swap(uvalue& other) noexcept; - [[nodiscard]] const any_type& get_type() const noexcept; + [[nodiscard]] any_type get_type() const noexcept; [[nodiscard]] void* get_data() noexcept; [[nodiscard]] const void* get_data() const noexcept; diff --git a/headers/meta.hpp/meta_uvalue/uvalue.hpp b/headers/meta.hpp/meta_uvalue/uvalue.hpp index 2661890..3ef2618 100644 --- a/headers/meta.hpp/meta_uvalue/uvalue.hpp +++ b/headers/meta.hpp/meta_uvalue/uvalue.hpp @@ -345,10 +345,9 @@ namespace meta_hpp vtable_t::do_swap(*this, other); } - inline const any_type& uvalue::get_type() const noexcept { - static any_type void_type = resolve_type(); + inline any_type uvalue::get_type() const noexcept { auto&& [tag, vtable] = vtable_t::unpack_vtag(*this); - return tag == storage_e::nothing ? void_type : vtable->type; + return tag == storage_e::nothing ? any_type{} : vtable->type; } inline void* uvalue::get_data() noexcept {