Преглед изворни кода

removed potentially ambiguous call (fix #203)

Michele Caini пре 7 година
родитељ
комит
330d553ffb

+ 3 - 3
src/entt/entity/registry.hpp

@@ -72,8 +72,8 @@ class basic_registry {
         }
 
         template<typename It>
-        Component * construct(It first, It last, typename sparse_set<Entity>::size_type hint) {
-            auto *component = sparse_set<Entity, Component>::construct(first, last, hint);
+        Component * batch(It first, It last, typename sparse_set<Entity>::size_type hint) {
+            auto *component = sparse_set<Entity, Component>::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<Component>()->construct(first, last, hint)... };
+            return { assure<Component>()->batch(first, last, hint)... };
         }
     }
 

+ 4 - 4
src/entt/entity/sparse_set.hpp

@@ -389,7 +389,7 @@ public:
      * @param hint Hint value to avoid searching for the largest entity.
      */
     template<typename It>
-    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<typename It>
-    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<object_type>) {
-            underlying_type::construct(first, last, hint);
+            underlying_type::batch(first, last, hint);
             return &instances;
         } else {
             static_assert(std::is_default_constructible_v<object_type>);
             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;
         }
     }

+ 11 - 0
test/entt/entity/registry.cpp

@@ -3,6 +3,7 @@
 #include <functional>
 #include <iterator>
 #include <memory>
+#include <cstdint>
 #include <type_traits>
 #include <gtest/gtest.h>
 #include <entt/entity/entt_traits.hpp>
@@ -1216,3 +1217,13 @@ TEST(Registry, Constness) {
     ASSERT_TRUE((std::is_same_v<decltype(std::as_const(registry).try_get<int>({})), const int *>));
     ASSERT_TRUE((std::is_same_v<decltype(std::as_const(registry).try_get<int, char>({})), std::tuple<const int *, const char *>>));
 }
+
+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<ambiguous>(entity, foo, bar);
+}

+ 6 - 6
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<std::uint64_t> set;
     entt::sparse_set<std::uint64_t>::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<std::uint64_t, int> set;
     entt::sparse_set<std::uint64_t>::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<std::uint64_t, empty_type> set;
     entt::sparse_set<std::uint64_t>::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]));