diff --git a/src/entt/entity/registry.hpp b/src/entt/entity/registry.hpp index a861918d3..0828a1b09 100644 --- a/src/entt/entity/registry.hpp +++ b/src/entt/entity/registry.hpp @@ -72,8 +72,8 @@ class basic_registry { } template - Component * construct(It first, It last, typename sparse_set::size_type hint) { - auto *component = sparse_set::construct(first, last, hint); + Component * batch(It first, It last, typename sparse_set::size_type hint) { + auto *component = sparse_set::batch(first, last, hint); if(!construction.empty()) { std::for_each(first, last, [this](const auto entity) { @@ -596,7 +596,7 @@ public: if constexpr(sizeof...(Component) > 0) { const auto hint = size_type(std::max(candidate, *(last-1)))+1; - return { assure()->construct(first, last, hint)... }; + return { assure()->batch(first, last, hint)... }; } } diff --git a/src/entt/entity/sparse_set.hpp b/src/entt/entity/sparse_set.hpp index 293315759..c7d41b681 100644 --- a/src/entt/entity/sparse_set.hpp +++ b/src/entt/entity/sparse_set.hpp @@ -389,7 +389,7 @@ public: * @param hint Hint value to avoid searching for the largest entity. */ template - void construct(It first, It last, size_type hint) { + void batch(It first, It last, size_type hint) { if(hint > reverse.size()) { // null is safe in all cases for our purposes reverse.resize(hint, null); @@ -971,16 +971,16 @@ public: * same of the entities. */ template - object_type * construct(It first, It last, const size_type hint) { + object_type * batch(It first, It last, const size_type hint) { if constexpr(std::is_empty_v) { - underlying_type::construct(first, last, hint); + underlying_type::batch(first, last, hint); return &instances; } else { static_assert(std::is_default_constructible_v); const auto offset = instances.size(); instances.insert(instances.end(), last-first, {}); // entity goes after component in case constructor throws - underlying_type::construct(first, last, hint); + underlying_type::batch(first, last, hint); return instances.data() + offset; } } diff --git a/test/entt/entity/registry.cpp b/test/entt/entity/registry.cpp index d1ed91de6..46c5a1382 100644 --- a/test/entt/entity/registry.cpp +++ b/test/entt/entity/registry.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -1216,3 +1217,13 @@ TEST(Registry, Constness) { ASSERT_TRUE((std::is_same_v({})), const int *>)); ASSERT_TRUE((std::is_same_v({})), std::tuple>)); } + +TEST(Registry, BatchCreateAmbiguousCall) { + struct ambiguous { std::uint32_t foo; std::uint64_t bar; }; + entt::registry registry; + const auto entity = registry.create(); + std::uint32_t foo = 32u; + std::uint64_t bar = 64u; + // this should work, no other tests required + registry.assign(entity, foo, bar); +} diff --git a/test/entt/entity/sparse_set.cpp b/test/entt/entity/sparse_set.cpp index 31c5a9a6f..a5ff2f3de 100644 --- a/test/entt/entity/sparse_set.cpp +++ b/test/entt/entity/sparse_set.cpp @@ -61,7 +61,7 @@ TEST(SparseSetNoType, Functionalities) { other = std::move(set); } -TEST(SparseSetNoType, ConstructMany) { +TEST(SparseSetNoType, BatchAdd) { entt::sparse_set set; entt::sparse_set::entity_type entities[2]; @@ -69,7 +69,7 @@ TEST(SparseSetNoType, ConstructMany) { entities[1] = 42; set.construct(12); - set.construct(std::begin(entities), std::end(entities), 43); + set.batch(std::begin(entities), std::end(entities), 43); set.construct(24); ASSERT_TRUE(set.has(entities[0])); @@ -435,7 +435,7 @@ TEST(SparseSetWithType, EmptyType) { ASSERT_EQ(std::as_const(set).try_get(42), std::as_const(set).try_get(99)); } -TEST(SparseSetWithType, ConstructMany) { +TEST(SparseSetWithType, BatchAdd) { entt::sparse_set set; entt::sparse_set::entity_type entities[2]; @@ -444,7 +444,7 @@ TEST(SparseSetWithType, ConstructMany) { set.reserve(4); set.construct(12, 21); - auto *component = set.construct(std::begin(entities), std::end(entities), 43); + auto *component = set.batch(std::begin(entities), std::end(entities), 43); set.construct(24, 42); ASSERT_TRUE(set.has(entities[0])); @@ -468,7 +468,7 @@ TEST(SparseSetWithType, ConstructMany) { ASSERT_EQ(set.get(entities[1]), 2); } -TEST(SparseSetWithType, ConstructManyEmptyType) { +TEST(SparseSetWithType, BatchAddEmptyType) { entt::sparse_set set; entt::sparse_set::entity_type entities[2]; @@ -477,7 +477,7 @@ TEST(SparseSetWithType, ConstructManyEmptyType) { set.reserve(4); set.construct(12); - auto *component = set.construct(std::begin(entities), std::end(entities), 43); + auto *component = set.batch(std::begin(entities), std::end(entities), 43); set.construct(24); ASSERT_TRUE(set.has(entities[0]));