Explorar o código

sigh_mixin: avoid using weak ranges twice - close #1123

Michele Caini %!s(int64=2) %!d(string=hai) anos
pai
achega
02ec48ddc5
Modificáronse 2 ficheiros con 20 adicións e 2 borrados
  1. 3 2
      src/entt/entity/mixin.hpp
  2. 17 0
      test/entt/entity/sigh_mixin.cpp

+ 3 - 2
src/entt/entity/mixin.hpp

@@ -271,11 +271,12 @@ public:
      */
     template<typename It, typename... Args>
     void insert(It first, It last, Args &&...args) {
+        auto from = underlying_type::size();
         underlying_type::insert(first, last, std::forward<Args>(args)...);
 
         if(auto &reg = owner_or_assert(); !construction.empty()) {
-            for(; first != last; ++first) {
-                construction.publish(reg, *first);
+            for(const auto to = underlying_type::size(); from != to; ++from) {
+                construction.publish(reg, underlying_type::operator[](from));
             }
         }
     }

+ 17 - 0
test/entt/entity/sigh_mixin.cpp

@@ -115,6 +115,23 @@ TYPED_TEST(SighMixin, Functionalities) {
     ASSERT_EQ(pool.size(), 0u);
 }
 
+TYPED_TEST(SighMixin, InsertWeakRange) {
+    using value_type = typename TestFixture::type;
+
+    entt::registry registry;
+    auto &pool = registry.storage<value_type>();
+    const auto view = registry.view<entt::entity>(entt::exclude<value_type>);
+    [[maybe_unused]] const std::array entity{registry.create(), registry.create()};
+    std::size_t on_construct{};
+
+    ASSERT_EQ(on_construct, 0u);
+
+    pool.on_construct().template connect<&listener<entt::registry>>(on_construct);
+    pool.insert(view.begin(), view.end());
+
+    ASSERT_EQ(on_construct, 2u);
+}
+
 TEST(SighMixin, NonDefaultConstructibleType) {
     entt::registry registry;
     auto &pool = registry.storage<test::non_default_constructible>();