From 33b598289b5e446c81435492b95189b68151e27d Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Wed, 20 Sep 2023 14:51:14 +0200 Subject: [PATCH] meta: help the code coverage tool --- src/entt/meta/meta.hpp | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/entt/meta/meta.hpp b/src/entt/meta/meta.hpp index 6612b4508..757b707a5 100644 --- a/src/entt/meta/meta.hpp +++ b/src/entt/meta/meta.hpp @@ -501,7 +501,7 @@ public: * @return True if there exists a viable conversion, false otherwise. */ template - bool allow_cast() { + [[nodiscard]] bool allow_cast() { auto other = internal::resolve>>(internal::meta_context::from(*ctx)); return allow_cast(meta_type{*ctx, other}) && (!(std::is_reference_v && !std::is_const_v>) || storage.data() != nullptr); } @@ -1858,16 +1858,10 @@ inline bool meta_sequence_container::reserve(const size_type sz) { * @return A possibly invalid iterator to the inserted element. */ inline meta_sequence_container::iterator meta_sequence_container::insert(iterator it, meta_any value) { - if(storage.policy() != any_policy::cref) { - // this abomination is necessary because only on macos value_type and const_reference are different types for std::vector - if(value.allow_cast(meta_type{*ctx, value_type_node(internal::meta_context::from(*ctx))})) { - if(insert_fn(storage.data(), std::as_const(value).data(), nullptr, it)) { - return it; - } - } else if(value.allow_cast(meta_type{*ctx, const_reference_node(internal::meta_context::from(*ctx))})) { - if(insert_fn(storage.data(), nullptr, std::as_const(value).data(), it)) { - return it; - } + // 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)); (storage.policy() != any_policy::cref) && (value.allow_cast({*ctx, vtype}) || value.allow_cast({*ctx, const_reference_node(internal::meta_context::from(*ctx))}))) { + if(const bool is_value_type = (value.type().info() == *vtype.info); insert_fn(storage.data(), is_value_type ? std::as_const(value).data() : nullptr, is_value_type ? nullptr : std::as_const(value).data(), it)) { + return it; } }