return an empty type for empty uvalues

This commit is contained in:
BlackMATov
2023-02-08 06:22:45 +07:00
parent 24657755eb
commit 178a4486cf
4 changed files with 7 additions and 9 deletions

View File

@@ -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<void>();
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 {

View File

@@ -178,7 +178,7 @@ TEST_CASE("meta/meta_utilities/value") {
CHECK_THROWS(std::ignore = std::move(std::as_const(val)).get_as<int>());
}
CHECK(meta::uvalue{}.get_type() == meta::resolve_type<void>());
CHECK_FALSE(meta::uvalue{}.get_type());
}
SUBCASE("ivec2&") {

View File

@@ -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;

View File

@@ -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<void>();
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 {