Przeglądaj źródła

multi-component registry::shrink_to_fit

Michele Caini 6 lat temu
rodzic
commit
ee373eb6fb
2 zmienionych plików z 6 dodań i 6 usunięć
  1. 5 4
      src/entt/entity/registry.hpp
  2. 1 2
      test/entt/entity/registry.cpp

+ 5 - 4
src/entt/entity/registry.hpp

@@ -425,12 +425,13 @@ public:
     }
 
     /**
-     * @brief Requests the removal of unused capacity for a given component.
-     * @tparam Component Type of component for which to reclaim unused capacity.
+     * @brief Requests the removal of unused capacity for the given components.
+     * @tparam Component Types of components for which to reclaim unused
+     * capacity.
      */
-    template<typename Component>
+    template<typename... Component>
     void shrink_to_fit() {
-        assure<Component>()->shrink_to_fit();
+        (assure<Component>()->shrink_to_fit(), ...);
     }
 
     /**

+ 1 - 2
test/entt/entity/registry.cpp

@@ -245,8 +245,7 @@ TEST(Registry, Functionalities) {
     ASSERT_EQ(registry.capacity<int>(), entt::registry::size_type{8});
     ASSERT_EQ(registry.capacity<char>(), entt::registry::size_type{8});
 
-    registry.shrink_to_fit<int>();
-    registry.shrink_to_fit<char>();
+    registry.shrink_to_fit<int, char>();
 
     ASSERT_EQ(registry.capacity<int>(), entt::registry::size_type{});
     ASSERT_EQ(registry.capacity<char>(), entt::registry::size_type{});