Browse Source

sparse_set/storage: support entity and component types with custom swap functions

Michele Caini 4 years ago
parent
commit
c0251f5c29
2 changed files with 9 additions and 3 deletions
  1. 7 2
      src/entt/entity/sparse_set.hpp
  2. 2 1
      src/entt/entity/storage.hpp

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

@@ -752,7 +752,10 @@ public:
             if(const size_type to = entity_traits::to_entity(*it); to < from) {
                 --from;
                 move_element(from, to);
-                std::swap(packed[from], packed[to]);
+
+                using std::swap;
+                swap(packed[from], packed[to]);
+                
                 const auto entity = static_cast<typename entity_traits::entity_type>(to);
                 sparse_ref(packed[to]) = entity_traits::combine(entity, entity_traits::to_integral(packed[to]));
                 *it = entity_traits::combine(static_cast<typename entity_traits::entity_type>(from), entity_traits::reserved);
@@ -790,7 +793,9 @@ public:
         swap_at(static_cast<size_type>(from), static_cast<size_type>(to));
         entt = entity_traits::combine(to, entity_traits::to_integral(packed[from]));
         other = entity_traits::combine(from, entity_traits::to_integral(packed[to]));
-        std::swap(packed[from], packed[to]);
+
+        using std::swap;
+        swap(packed[from], packed[to]);
     }
 
     /**

+ 2 - 1
src/entt/entity/storage.hpp

@@ -317,7 +317,8 @@ private:
     }
 
     void swap_at(const std::size_t lhs, const std::size_t rhs) final {
-        std::swap(element_at(lhs), element_at(rhs));
+        using std::swap;
+        swap(element_at(lhs), element_at(rhs));
     }
 
     void move_element(const std::size_t from, const std::size_t to) final {