Browse Source

sparse_set: entity ::swap -> ::swap_elements

Michele Caini 4 years ago
parent
commit
6f546ffe95

+ 1 - 1
src/entt/entity/group.hpp

@@ -952,7 +952,7 @@ public:
             for(auto next = *length; next; --next) {
             for(auto next = *length; next; --next) {
                 const auto pos = next - 1;
                 const auto pos = next - 1;
                 [[maybe_unused]] const auto entt = head->data()[pos];
                 [[maybe_unused]] const auto entt = head->data()[pos];
-                (other->swap(other->data()[pos], entt), ...);
+                (other->swap_elements(other->data()[pos], entt), ...);
             }
             }
         }(std::get<storage_type<Owned> *>(pools)...);
         }(std::get<storage_type<Owned> *>(pools)...);
     }
     }

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

@@ -79,7 +79,7 @@ class basic_registry {
             } else {
             } else {
                 if(is_valid && !(std::get<0>(cpools)->index(entt) < current)) {
                 if(is_valid && !(std::get<0>(cpools)->index(entt) < current)) {
                     const auto pos = current++;
                     const auto pos = current++;
-                    (std::get<storage_type<Owned> *>(cpools)->swap(std::get<storage_type<Owned> *>(cpools)->data()[pos], entt), ...);
+                    (std::get<storage_type<Owned> *>(cpools)->swap_elements(std::get<storage_type<Owned> *>(cpools)->data()[pos], entt), ...);
                 }
                 }
             }
             }
         }
         }
@@ -90,7 +90,7 @@ class basic_registry {
             } else {
             } else {
                 if(const auto cpools = std::make_tuple(owner.assure<Owned>()...); std::get<0>(cpools)->contains(entt) && (std::get<0>(cpools)->index(entt) < current)) {
                 if(const auto cpools = std::make_tuple(owner.assure<Owned>()...); std::get<0>(cpools)->contains(entt) && (std::get<0>(cpools)->index(entt) < current)) {
                     const auto pos = --current;
                     const auto pos = --current;
-                    (std::get<storage_type<Owned> *>(cpools)->swap(std::get<storage_type<Owned> *>(cpools)->data()[pos], entt), ...);
+                    (std::get<storage_type<Owned> *>(cpools)->swap_elements(std::get<storage_type<Owned> *>(cpools)->data()[pos], entt), ...);
                 }
                 }
             }
             }
         }
         }

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

@@ -786,7 +786,7 @@ public:
      * @param lhs A valid identifier.
      * @param lhs A valid identifier.
      * @param rhs A valid identifier.
      * @param rhs A valid identifier.
      */
      */
-    void swap(const entity_type lhs, const entity_type rhs) {
+    void swap_elements(const entity_type lhs, const entity_type rhs) {
         ENTT_ASSERT(contains(lhs) && contains(rhs), "Set does not contain entities");
         ENTT_ASSERT(contains(lhs) && contains(rhs), "Set does not contain entities");
 
 
         auto &entt = sparse_array[page(lhs)][offset(lhs)];
         auto &entt = sparse_array[page(lhs)][offset(lhs)];
@@ -898,7 +898,7 @@ public:
             if(contains(*from)) {
             if(contains(*from)) {
                 if(*from != packed_array[pos]) {
                 if(*from != packed_array[pos]) {
                     // basic no-leak guarantee (with invalid state) if swapping throws
                     // basic no-leak guarantee (with invalid state) if swapping throws
-                    swap(packed_array[pos], *from);
+                    swap_elements(packed_array[pos], *from);
                 }
                 }
 
 
                 --pos;
                 --pos;

+ 4 - 4
test/entt/entity/sparse_set.cpp

@@ -750,15 +750,15 @@ TEST(SparseSet, SwapEntity) {
     ASSERT_EQ(set.index(traits_type::construct(3, 5)), 0u);
     ASSERT_EQ(set.index(traits_type::construct(3, 5)), 0u);
     ASSERT_EQ(set.index(traits_type::construct(42, 99)), 1u);
     ASSERT_EQ(set.index(traits_type::construct(42, 99)), 1u);
 
 
-    ASSERT_DEATH(set.swap(traits_type::construct(3, 5), traits_type::construct(42, 98)), "");
-    ASSERT_DEATH(set.swap(traits_type::construct(3, 6), traits_type::construct(42, 99)), "");
+    ASSERT_DEATH(set.swap_elements(traits_type::construct(3, 5), traits_type::construct(42, 98)), "");
+    ASSERT_DEATH(set.swap_elements(traits_type::construct(3, 6), traits_type::construct(42, 99)), "");
 
 
-    set.swap(traits_type::construct(3, 5), traits_type::construct(42, 99));
+    set.swap_elements(traits_type::construct(3, 5), traits_type::construct(42, 99));
 
 
     ASSERT_EQ(set.index(traits_type::construct(3, 5)), 1u);
     ASSERT_EQ(set.index(traits_type::construct(3, 5)), 1u);
     ASSERT_EQ(set.index(traits_type::construct(42, 99)), 0u);
     ASSERT_EQ(set.index(traits_type::construct(42, 99)), 0u);
 
 
-    set.swap(traits_type::construct(3, 5), traits_type::construct(42, 99));
+    set.swap_elements(traits_type::construct(3, 5), traits_type::construct(42, 99));
 
 
     ASSERT_EQ(set.index(traits_type::construct(3, 5)), 0u);
     ASSERT_EQ(set.index(traits_type::construct(3, 5)), 0u);
     ASSERT_EQ(set.index(traits_type::construct(42, 99)), 1u);
     ASSERT_EQ(set.index(traits_type::construct(42, 99)), 1u);