From 31808bd9a2ada3a89f6b5891a54d3628450b8e8f Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Mon, 27 Mar 2023 17:01:14 +0200 Subject: [PATCH] sigh: flip the last commit on its head and drop redundant functions rather than merging them --- src/entt/entity/observer.hpp | 20 ++++++++++---------- src/entt/signal/sigh.hpp | 16 +++++----------- test/entt/signal/sigh.cpp | 4 ++-- 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/src/entt/entity/observer.hpp b/src/entt/entity/observer.hpp index 61775aa67..9ce5c1828 100644 --- a/src/entt/entity/observer.hpp +++ b/src/entt/entity/observer.hpp @@ -195,10 +195,10 @@ class basic_observer: private basic_storage().disconnect(obs), ...); - (reg.template on_construct().disconnect(obs), ...); - reg.template on_update().disconnect(obs); - reg.template on_destroy().disconnect(obs); + (reg.template on_destroy().disconnect(&obs), ...); + (reg.template on_construct().disconnect(&obs), ...); + reg.template on_update().disconnect(&obs); + reg.template on_destroy().disconnect(&obs); } }; @@ -241,12 +241,12 @@ class basic_observer: private basic_storage().disconnect(obs), ...); - (reg.template on_construct().disconnect(obs), ...); - (reg.template on_construct().disconnect(obs), ...); - (reg.template on_destroy().disconnect(obs), ...); - (reg.template on_destroy().disconnect(obs), ...); - (reg.template on_construct().disconnect(obs), ...); + (reg.template on_destroy().disconnect(&obs), ...); + (reg.template on_construct().disconnect(&obs), ...); + (reg.template on_construct().disconnect(&obs), ...); + (reg.template on_destroy().disconnect(&obs), ...); + (reg.template on_destroy().disconnect(&obs), ...); + (reg.template on_construct().disconnect(&obs), ...); } }; diff --git a/src/entt/signal/sigh.hpp b/src/entt/signal/sigh.hpp index 136aa6fca..05002f30e 100644 --- a/src/entt/signal/sigh.hpp +++ b/src/entt/signal/sigh.hpp @@ -508,19 +508,13 @@ public: /** * @brief Disconnects free functions with payload or bound members from a * signal. - * @tparam Type Type of class or type of payload. * @param value_or_instance A valid object that fits the purpose. */ - template - void disconnect(Type &&value_or_instance) { - if constexpr(std::is_pointer_v>) { - if(value_or_instance) { - auto &calls = signal->calls; - auto predicate = [value_or_instance](const auto &delegate) { return delegate.data() == value_or_instance; }; - calls.erase(std::remove_if(calls.begin(), calls.end(), std::move(predicate)), calls.end()); - } - } else { - disconnect(&value_or_instance); + void disconnect(const void *value_or_instance) { + if(value_or_instance) { + auto &calls = signal->calls; + auto predicate = [value_or_instance](const auto &delegate) { return delegate.data() == value_or_instance; }; + calls.erase(std::remove_if(calls.begin(), calls.end(), std::move(predicate)), calls.end()); } } diff --git a/test/entt/signal/sigh.cpp b/test/entt/signal/sigh.cpp index 1097fc4f7..b9b3c1797 100644 --- a/test/entt/signal/sigh.cpp +++ b/test/entt/signal/sigh.cpp @@ -171,7 +171,7 @@ TEST_F(SigH, FunctionsWithPayload) { ASSERT_EQ(v, 0); sink.connect<&sigh_listener::f>(v); - sink.disconnect(v); + sink.disconnect(&v); sigh.publish(); ASSERT_EQ(v, 0); @@ -542,7 +542,7 @@ TEST_F(SigH, CustomAllocator) { sink.template connect<&sigh_listener::g>(listener); decltype(sigh) copy{sigh, allocator}; - sink.disconnect(listener); + sink.disconnect(&listener); ASSERT_TRUE(sigh.empty()); ASSERT_FALSE(copy.empty());