Skip to content

Commit

Permalink
sigh_mixin: avoid using weak ranges twice - close #1123
Browse files Browse the repository at this point in the history
  • Loading branch information
skypjack committed Mar 14, 2024
1 parent 369bebd commit 02ec48d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/entt/entity/mixin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,12 @@ class basic_sigh_mixin final: public Type {
*/
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));
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions test/entt/entity/sigh_mixin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>();
Expand Down

0 comments on commit 02ec48d

Please sign in to comment.