diff --git a/src/entt/entity/storage.hpp b/src/entt/entity/storage.hpp index b677c98ef..e20979793 100644 --- a/src/entt/entity/storage.hpp +++ b/src/entt/entity/storage.hpp @@ -647,7 +647,35 @@ struct storage_adapter_mixin: Type { * @tparam Type The type of the underlying storage. */ template -struct sigh_storage_mixin: Type { +class sigh_storage_mixin: public Type { + template + auto dispatch_emplace(int, basic_registry &owner, const typename Type::entity_type entity, Args &&... args) + -> std::enable_if_t().emplace(owner, entity, std::forward(args)...))>> { + Type::emplace(owner, entity, std::forward(args)...); + construction.publish(owner, entity); + } + + template + decltype(auto) dispatch_emplace(double, basic_registry &owner, const typename Type::entity_type entity, Args &&... args) { + Type::emplace(owner, entity, std::forward(args)...); + construction.publish(owner, entity); + return this->get(entity); + } + + template + auto dispatch_patch(int, basic_registry &owner, const typename Type::entity_type entity, Func &&... func) + -> decltype(std::declval().patch(owner, entity, std::forward(func)...)) { + Type::patch(owner, entity, std::forward(func)...); + update.publish(owner, entity); + return this->get(entity); + } + + template + void dispatch_patch(double, basic_registry &owner, const typename Type::entity_type entity, Func &&...) { + update.publish(owner, entity); + } + +public: /*! @brief Underlying value type. */ using value_type = typename Type::value_type; /*! @brief Underlying entity identifier. */ @@ -728,12 +756,7 @@ struct sigh_storage_mixin: Type { */ template decltype(auto) emplace(basic_registry &owner, const entity_type entity, Args &&... args) { - Type::emplace(owner, entity, std::forward(args)...); - construction.publish(owner, entity); - - if constexpr(std::tuple_size_v != 0) { - return this->get(entity); - } + return dispatch_emplace(0, owner, entity, std::forward(args)...); } /** @@ -795,14 +818,8 @@ struct sigh_storage_mixin: Type { * @return A reference to the patched instance. */ template - decltype(auto) patch(basic_registry &owner, const entity_type entity, [[maybe_unused]] Func &&... func) { - if constexpr(std::tuple_size_v == 0) { - update.publish(owner, entity); - } else { - Type::patch(owner, entity, std::forward(func)...); - update.publish(owner, entity); - return this->get(entity); - } + decltype(auto) patch(basic_registry &owner, const entity_type entity, Func &&... func) { + return dispatch_patch(0, owner, entity, std::forward(func)...); } private: