Skip to content

Commit

Permalink
meta: meta_sequence_container::resize support to non default construc…
Browse files Browse the repository at this point in the history
…tible types (close #1072)
  • Loading branch information
skypjack committed Oct 5, 2023
1 parent 33ef814 commit 8848040
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/entt/meta/container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ struct basic_meta_sequence_container_traits {
* @return True in case of success, false otherwise.
*/
[[nodiscard]] static bool resize([[maybe_unused]] void *container, [[maybe_unused]] const size_type sz) {
if constexpr(internal::dynamic_sequence_container_v<Type>) {
if constexpr(internal::dynamic_sequence_container_v<Type> && std::is_default_constructible_v<typename Type::value_type>) {
static_cast<Type *>(container)->resize(sz);
return true;
} else {
Expand Down
12 changes: 12 additions & 0 deletions test/entt/meta/meta_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@

struct invalid {};

struct non_default_constructible {
non_default_constructible() = delete;
};

TEST(MetaContainer, Invalid) {
ASSERT_FALSE(entt::meta_any{42}.as_sequence_container());
ASSERT_FALSE(entt::meta_any{42}.as_associative_container());
Expand Down Expand Up @@ -319,6 +323,14 @@ TEST(SequenceContainer, StdDeque) {
ASSERT_EQ(view.size(), 0u);
}

TEST(SequenceContainer, NonDefaultConstructible) {
std::vector<non_default_constructible> vec{};
auto any = entt::forward_as_meta(vec);
auto view = any.as_sequence_container();

ASSERT_FALSE(view.resize(5u));
}

TEST(SequenceContainer, Constness) {
std::vector<int> vec{};
auto any = entt::forward_as_meta(std::as_const(vec));
Expand Down

0 comments on commit 8848040

Please sign in to comment.