diff --git a/docs/signal.md b/docs/signal.md
index b923a1881..6f53fa922 100644
--- a/docs/signal.md
+++ b/docs/signal.md
@@ -90,12 +90,9 @@ signal.sink().connect<&listener::bar>(&instance);
// disconnects a free function
signal.sink().disconnect<&foo>();
-// disconnect a specific member function of an instance ...
+// disconnect a member function of an instance
signal.sink().disconnect<&listener::bar>(&instance);
-// ... or an instance as a whole
-signal.sink().disconnect(&instance);
-
// discards all the listeners at once
signal.sink().disconnect();
```
@@ -187,10 +184,22 @@ my_struct instance;
delegate.connect<&my_struct::f>(&instance);
```
-It hasn't a `disconnect` counterpart. Instead, there exists a `reset` member
-function to clear it.
-To know if a delegate is empty, it can be used explicitly in every conditional
-statement:
+The delegate class accepts also data members if required. In this case, the
+function type of the delegate is such that the parameter list is empty and the
+value of the data member is at least convertible to the return type.
+Finally, it can work with invokable objects in general (lambdas or functors), as
+long as they are trivially destructible and their sizes fit the one of `void *`.
+As an example, a lambda that captures a pointer or an integer value can be used
+with a delegate:
+
+```cpp
+delegate.connect([value = int_var](int i) { return value * i; });
+```
+
+Aside `connect`, a `disconnect` counterpart isn't provided. Instead, there
+exists a `reset` member function to use to clear a delegate.
+To know if it's empty instead, the delegate can be used explicitly in every
+conditional statement:
```cpp
if(delegate) {
@@ -268,11 +277,8 @@ In order to register an instance of a class to a dispatcher, its type must
expose one or more member functions the arguments of which are such that
`const E &` can be converted to them for each type of event `E`, no matter what
the return value is.
-To ease the development, member functions that are named `receive` are
-automatically detected and have not to be explicitly specified when registered.
-In all the other cases, the name of the member function aimed to receive the
-event must be provided to the `connect` member function of the sink bound to the
-specific event:
+The name of the member function aimed to receive the event must be provided to
+the `connect` member function of the sink in charge for the specific event:
```cpp
struct an_event { int value; };
@@ -287,7 +293,7 @@ struct listener
// ...
listener listener;
-dispatcher.sink().connect(&listener);
+dispatcher.sink().connect<&listener::receive>(&listener);
dispatcher.sink().connect<&listener::method>(&listener);
```
@@ -295,7 +301,7 @@ The `disconnect` member function follows the same pattern and can be used to
selectively remove listeners:
```cpp
-dispatcher.sink().disconnect(&listener);
+dispatcher.sink().disconnect<&listener::receive>(&listener);
dispatcher.sink().disconnect<&listener::method>(&listener);
```
diff --git a/src/entt/signal/delegate.hpp b/src/entt/signal/delegate.hpp
index 09b5c9979..7e4e98518 100644
--- a/src/entt/signal/delegate.hpp
+++ b/src/entt/signal/delegate.hpp
@@ -25,16 +25,16 @@ template
auto to_function_pointer(Ret(*)(Args...)) -> Ret(*)(Args...);
-template
-auto to_function_pointer(Ret(Class:: *)(Args...)) -> Ret(*)(Args...);
+template
+auto to_function_pointer(Ret(*)(Type, Args...), Value) -> Ret(*)(Args...);
template
-auto to_function_pointer(Ret(Class:: *)(Args...) const) -> Ret(*)(Args...);
+auto to_function_pointer(Ret(Class:: *)(Args...), Class *) -> Ret(*)(Args...);
-template
-using function_type = std::remove_pointer_t;
+template
+auto to_function_pointer(Ret(Class:: *)(Args...) const, Class *) -> Ret(*)(Args...);
}
@@ -80,7 +80,7 @@ class delegate;
* @tparam Args Types of arguments of a function type.
*/
template
-class delegate final {
+class delegate {
using storage_type = std::aligned_storage_t;
using proto_fn_type = Ret(storage_type &, Args...);
@@ -107,16 +107,32 @@ public:
}
/**
- * @brief Constructs a delegate and connects a member function to it.
- * @tparam Member Member function to connect to the delegate.
- * @tparam Class Type of class to which the member function belongs.
- * @param instance A valid instance of type pointer to `Class`.
+ * @brief Constructs a delegate and connects a member function for a given
+ * instance or a curried free function to it.
+ * @tparam Candidate Member function or curried free function to connect to
+ * the delegate.
+ * @tparam Type Type of class to which the member function belongs or type
+ * of value used for currying.
+ * @param value_or_instance A valid pointer to an instance of class type or
+ * the value to use for currying.
*/
- template>>
- delegate(connect_arg_t, Class *instance) ENTT_NOEXCEPT
+ template
+ delegate(connect_arg_t, Type value_or_instance) ENTT_NOEXCEPT
: delegate{}
{
- connect(instance);
+ connect(value_or_instance);
+ }
+
+ /**
+ * @brief Constructs a delegate and connects a lambda or a functor to it.
+ * @tparam Invokable Type of lambda or functor to connect.
+ * @param invokable A valid instance of the given type.
+ */
+ template
+ delegate(Invokable invokable) ENTT_NOEXCEPT
+ : delegate{}
+ {
+ connect(std::move(invokable));
}
/**
@@ -168,6 +184,25 @@ public:
};
}
+ /**
+ * @brief Connects a lambda or a functor to a delegate.
+ * @tparam Invokable Type of lambda or functor to connect.
+ * @param invokable A valid instance of the given type.
+ */
+ template
+ void connect(Invokable invokable) ENTT_NOEXCEPT {
+ static_assert(sizeof(Invokable) < sizeof(void *));
+ static_assert(std::is_class_v);
+ static_assert(std::is_trivially_destructible_v);
+ static_assert(std::is_invocable_r_v);
+ new (&storage) Invokable{std::move(invokable)};
+
+ fn = [](storage_type &storage, Args... args) -> Ret {
+ Invokable &invokable = *reinterpret_cast(&storage);
+ return std::invoke(invokable, args...);
+ };
+ }
+
/**
* @brief Resets a delegate.
*
@@ -220,14 +255,17 @@ public:
}
/**
- * @brief Checks if the contents of the two delegates are different.
+ * @brief Checks if the connected functions differ.
+ *
+ * In case of member functions, the instances connected to the delegate
+ * are not verified by this operator. Use the instance member function
+ * instead.
+ *
* @param other Delegate with which to compare.
- * @return True if the two delegates are identical, false otherwise.
+ * @return False if the connected functions differ, true otherwise.
*/
bool operator==(const delegate &other) const ENTT_NOEXCEPT {
- auto *lhs = reinterpret_cast(&storage);
- auto *rhs = reinterpret_cast(&other.storage);
- return fn == other.fn && std::equal(lhs, lhs + sizeof(storage_type), rhs);
+ return fn == other.fn;
}
private:
@@ -237,12 +275,16 @@ private:
/**
- * @brief Checks if the contents of the two delegates are different.
+ * @brief Checks if the connected functions differ.
+ *
+ * In case of member functions, the instances connected to the delegate are not
+ * verified by this operator. Use the `instance` member function instead.
+ *
* @tparam Ret Return type of a function type.
* @tparam Args Types of arguments of a function type.
* @param lhs A valid delegate object.
* @param rhs A valid delegate object.
- * @return True if the two delegates are different, false otherwise.
+ * @return True if the connected functions differ, false otherwise.
*/
template
bool operator!=(const delegate &lhs, const delegate &rhs) ENTT_NOEXCEPT {
@@ -253,27 +295,44 @@ bool operator!=(const delegate &lhs, const delegate
/**
* @brief Deduction guideline.
*
- * It allows to deduce the function type of the delegate directly from the
+ * It allows to deduce the function type of the delegate directly from a
* function provided to the constructor.
*
* @tparam Function A valid free function pointer.
*/
template
-delegate(connect_arg_t) ENTT_NOEXCEPT -> delegate>;
+delegate(connect_arg_t) ENTT_NOEXCEPT
+-> delegate>;
/**
-
* @brief Deduction guideline.
*
- * It allows to deduce the function type of the delegate directly from the
- * member function provided to the constructor.
+ * It allows to deduce the function type of the delegate directly from a member
+ * function or a curried free function provided to the constructor.
*
- * @tparam Member Member function to connect to the delegate.
- * @tparam Class Type of class to which the member function belongs.
+ * @tparam Candidate Member function or curried free function to connect to
+ * the delegate.
+ * @tparam Type Type of class to which the member function belongs or type
+ * of value used for currying.
*/
-template
-delegate(connect_arg_t, Class *) ENTT_NOEXCEPT -> delegate>;
+template
+delegate(connect_arg_t, Type) ENTT_NOEXCEPT
+-> delegate()))>>;
+
+
+/**
+ * @brief Deduction guideline.
+ *
+ * It allows to deduce the function type of the delegate directly from a lambda
+ * or a functor provided to the constructor.
+ *
+ * @tparam Invokable Type of lambda or functor to connect.
+ * @param invokable A valid instance of the given type.
+ */
+template
+delegate(Invokable invokable) ENTT_NOEXCEPT
+-> delegate>;
}
diff --git a/src/entt/signal/dispatcher.hpp b/src/entt/signal/dispatcher.hpp
index 1ae6e473e..c385dd4af 100644
--- a/src/entt/signal/dispatcher.hpp
+++ b/src/entt/signal/dispatcher.hpp
@@ -24,15 +24,14 @@ namespace entt {
* type `const Event &` plus an extra list of arguments to forward with the
* event itself, no matter what the return type is.
*
- * Member functions named `receive` are automatically detected and registered or
- * unregistered by the dispatcher. The type of the instances is `Class *` (a
- * naked pointer). It means that users must guarantee that the lifetimes of the
- * instances overcome the one of the dispatcher itself to avoid crashes.
+ * The type of the instances is `Class *` (a naked pointer). It means that users
+ * must guarantee that the lifetimes of the instances overcome the one of the
+ * dispatcher itself to avoid crashes.
*
* @tparam Args Types of arguments to forward along with an event.
*/
template
-class dispatcher final {
+class dispatcher {
using event_family = family;
template
@@ -44,7 +43,7 @@ class dispatcher final {
};
template
- struct signal_wrapper final: base_wrapper {
+ struct signal_wrapper: base_wrapper {
using signal_type = sigh;
using sink_type = typename signal_type::sink_type;
diff --git a/src/entt/signal/emitter.hpp b/src/entt/signal/emitter.hpp
index 1d0c76208..7af4452c5 100644
--- a/src/entt/signal/emitter.hpp
+++ b/src/entt/signal/emitter.hpp
@@ -49,7 +49,7 @@ class emitter {
};
template
- struct event_handler final: base_handler {
+ struct event_handler: base_handler {
using listener_type = std::function;
using element_type = std::pair;
using container_type = std::list;
@@ -145,7 +145,7 @@ public:
* @tparam Event Type of event for which the connection is created.
*/
template
- struct connection final: private event_handler::connection_type {
+ struct connection: private event_handler::connection_type {
/** @brief Event emitters are friend classes of connections. */
friend class emitter;
diff --git a/src/entt/signal/sigh.hpp b/src/entt/signal/sigh.hpp
index fcb7afd67..7e324bbd9 100644
--- a/src/entt/signal/sigh.hpp
+++ b/src/entt/signal/sigh.hpp
@@ -48,14 +48,14 @@ struct invoker {
template
-struct null_collector final {
+struct null_collector {
using result_type = Ret;
bool operator()(result_type) const ENTT_NOEXCEPT { return true; }
};
template<>
-struct null_collector final {
+struct null_collector {
using result_type = void;
bool operator()() const ENTT_NOEXCEPT { return true; }
};
@@ -66,7 +66,7 @@ struct default_collector;
template
-struct default_collector final {
+struct default_collector {
using collector_type = null_collector;
};
@@ -124,7 +124,7 @@ struct sigh;
* @tparam Args Types of arguments of a function type.
*/
template
-class sink final {
+class sink {
/*! @brief A signal is allowed to create sinks. */
template
friend struct sigh;
@@ -151,40 +151,39 @@ public:
}
/**
- * @brief Connects a member function for a given instance to a signal.
+ * @brief Connects a member function for a given instance or a curried free
+ * function to a signal.
*
- * The signal isn't responsible for the connected object. Users must
- * guarantee that the lifetime of the instance overcomes the one of the
- * signal. On the other side, the signal handler performs checks to avoid
- * multiple connections for the same member function of a given instance.
+ * When used to connect a member function, the signal isn't responsible for
+ * the connected object. Users must guarantee that the lifetime of the
+ * instance overcomes the one of the delegate. On the other side, the signal
+ * handler performs checks to avoid multiple connections for the same member
+ * function of a given instance.
+ * When used to connect a curried free function, the linked value must be
+ * both trivially copyable and trivially destructible, other than such that
+ * its size is lower than or equal to the one of a `void *`. It means that
+ * all the primitive types are accepted as well as pointers. Moreover, the
+ * signature of the free function must be such that the value is the first
+ * argument before the ones used to define the delegate itself.
*
- * @tparam Member Member function to connect to the signal.
- * @tparam Class Type of class to which the member function belongs.
- * @param instance A valid instance of type pointer to `Class`.
+ * @tparam Candidate Member function or curried free function to connect to
+ * the signal.
+ * @tparam Type Type of class to which the member function belongs or type
+ * of value used for currying.
+ * @param value_or_instance A valid pointer to an instance of class type or
+ * the value to use for currying.
*/
- template
- void connect(Class *instance) {
- disconnect(instance);
- delegate delegate{};
- delegate.template connect(instance);
- calls->emplace_back(std::move(delegate));
- }
+ template
+ void connect(Type value_or_instance) {
+ if constexpr(std::is_class_v>) {
+ disconnect(value_or_instance);
+ } else {
+ disconnect();
+ }
- /**
- * @brief Connects the `receive` member function for a given instance to a
- * signal.
- *
- * The signal isn't responsible for the connected object. Users must
- * guarantee that the lifetime of the instance overcomes the one of the
- * signal. On the other side, the signal handler performs checks to avoid
- * multiple connections for the same member function of a given instance.
- *
- * @tparam Class Type of class to which the member function belongs.
- * @param instance A valid instance of type pointer to `Class`.
- */
- template
- inline void connect(Class *instance) {
- connect<&Class::receive>(instance);
+ delegate delegate{};
+ delegate.template connect(value_or_instance);
+ calls->emplace_back(std::move(delegate));
}
/**
@@ -208,16 +207,9 @@ public:
void disconnect(Class *instance) {
delegate delegate{};
delegate.template connect(instance);
- calls->erase(std::remove(calls->begin(), calls->end(), std::move(delegate)), calls->end());
- }
-
- /**
- * @brief Removes all existing connections for the given instance.
- * @param instance An instance to be disconnected from the signal.
- */
- void disconnect(const void *instance) {
- auto func = [instance](const auto &delegate) { return delegate.instance() == instance; };
- calls->erase(std::remove_if(calls->begin(), calls->end(), std::move(func)), calls->end());
+ calls->erase(std::remove_if(calls->begin(), calls->end(), [&delegate](const auto &other) {
+ return other == delegate && other.instance() == delegate.instance();
+ }), calls->end());
}
/**
@@ -256,7 +248,7 @@ private:
* @tparam Collector Type of collector to use, if any.
*/
template
-struct sigh final: private internal::invoker {
+struct sigh: private internal::invoker {
/*! @brief Unsigned integer type. */
using size_type = typename std::vector>::size_type;
/*! @brief Collector type. */
@@ -341,42 +333,11 @@ struct sigh final: private internal::invoker> calls;
};
-/**
- * @brief Checks if the contents of the two signals are different.
- *
- * Two signals are identical if they have the same size and the same listeners
- * registered exactly in the same order.
- *
- * @tparam Ret Return type of a function type.
- * @tparam Args Types of arguments of a function type.
- * @param lhs A valid signal object.
- * @param rhs A valid signal object.
- * @return True if the two signals are different, false otherwise.
- */
-template
-bool operator!=(const sigh &lhs, const sigh &rhs) ENTT_NOEXCEPT {
- return !(lhs == rhs);
-}
-
-
}
diff --git a/test/entt/signal/delegate.cpp b/test/entt/signal/delegate.cpp
index 8a252f28f..03385a98c 100644
--- a/test/entt/signal/delegate.cpp
+++ b/test/entt/signal/delegate.cpp
@@ -22,6 +22,9 @@ struct delegate_functor {
int identity(int i) const {
return i;
}
+
+ static const int static_value = 3;
+ const int data_member = 42;
};
struct const_nonconst_noexcept {
@@ -69,6 +72,29 @@ TEST(Delegate, Functionalities) {
ASSERT_EQ(ff_del, mf_del);
}
+TEST(Delegate, DataMembers) {
+ entt::delegate delegate;
+ delegate_functor functor;
+
+ delegate.connect<&delegate_functor::data_member>(&functor);
+
+ ASSERT_EQ(delegate(), 42);
+}
+
+TEST(Delegate, LambdaAndFunctor) {
+ entt::delegate non_capturing_delegate;
+ entt::delegate capturing_delegate;
+ entt::delegate functor_delegate;
+
+ non_capturing_delegate.connect([](int v) { return v*v; });
+ capturing_delegate.connect([value = 5](int v) { return v*value; });
+ functor_delegate.connect(delegate_functor{});
+
+ ASSERT_EQ(non_capturing_delegate(3), 9);
+ ASSERT_EQ(capturing_delegate(3), 15);
+ ASSERT_EQ(functor_delegate(3), 6);
+}
+
TEST(Delegate, Comparison) {
entt::delegate lhs;
entt::delegate rhs;
@@ -80,6 +106,20 @@ TEST(Delegate, Comparison) {
ASSERT_TRUE(lhs == rhs);
ASSERT_EQ(lhs, rhs);
+ lhs.connect(functor);
+
+ ASSERT_EQ(lhs, entt::delegate{functor});
+ ASSERT_TRUE(lhs != rhs);
+ ASSERT_FALSE(lhs == rhs);
+ ASSERT_NE(lhs, rhs);
+
+ rhs.connect<>(functor);
+
+ ASSERT_EQ(rhs, entt::delegate{functor});
+ ASSERT_FALSE(lhs != rhs);
+ ASSERT_TRUE(lhs == rhs);
+ ASSERT_EQ(lhs, rhs);
+
lhs.connect<&delegate_function>();
ASSERT_EQ(lhs, entt::delegate{entt::connect_arg<&delegate_function>});
@@ -89,7 +129,21 @@ TEST(Delegate, Comparison) {
rhs.connect<&delegate_function>();
- ASSERT_EQ(lhs, entt::delegate{entt::connect_arg<&delegate_function>});
+ ASSERT_EQ(rhs, entt::delegate{entt::connect_arg<&delegate_function>});
+ ASSERT_FALSE(lhs != rhs);
+ ASSERT_TRUE(lhs == rhs);
+ ASSERT_EQ(lhs, rhs);
+
+ lhs.connect<&curried_function_by_value>(0);
+
+ ASSERT_EQ(lhs, (entt::delegate{entt::connect_arg<&curried_function_by_value>, 0}));
+ ASSERT_TRUE(lhs != rhs);
+ ASSERT_FALSE(lhs == rhs);
+ ASSERT_NE(lhs, rhs);
+
+ rhs.connect<&curried_function_by_value>(0);
+
+ ASSERT_EQ(rhs, (entt::delegate{entt::connect_arg<&curried_function_by_value>, 0}));
ASSERT_FALSE(lhs != rhs);
ASSERT_TRUE(lhs == rhs);
ASSERT_EQ(lhs, rhs);
@@ -103,7 +157,7 @@ TEST(Delegate, Comparison) {
rhs.connect<&delegate_functor::operator()>(&functor);
- ASSERT_EQ(lhs, (entt::delegate{entt::connect_arg<&delegate_functor::operator()>, &functor}));
+ ASSERT_EQ(rhs, (entt::delegate{entt::connect_arg<&delegate_functor::operator()>, &functor}));
ASSERT_FALSE(lhs != rhs);
ASSERT_TRUE(lhs == rhs);
ASSERT_EQ(lhs, rhs);
@@ -111,9 +165,10 @@ TEST(Delegate, Comparison) {
lhs.connect<&delegate_functor::operator()>(&other);
ASSERT_EQ(lhs, (entt::delegate{entt::connect_arg<&delegate_functor::operator()>, &other}));
- ASSERT_TRUE(lhs != rhs);
- ASSERT_FALSE(lhs == rhs);
- ASSERT_NE(lhs, rhs);
+ ASSERT_NE(lhs.instance(), rhs.instance());
+ ASSERT_FALSE(lhs != rhs);
+ ASSERT_TRUE(lhs == rhs);
+ ASSERT_EQ(lhs, rhs);
lhs.reset();
@@ -149,33 +204,34 @@ TEST(Delegate, ConstNonConstNoExcept) {
ASSERT_EQ(functor.cnt, 4);
}
-TEST(Delegate, Constructors) {
- delegate_functor functor;
- entt::delegate empty{};
- entt::delegate func{entt::connect_arg<&delegate_function>};
- entt::delegate member{entt::connect_arg<&delegate_functor::operator()>, &functor};
-
- ASSERT_FALSE(empty);
- ASSERT_TRUE(func);
- ASSERT_TRUE(member);
-}
-
TEST(Delegate, DeducedGuidelines) {
const_nonconst_noexcept functor;
+ entt::delegate invokable_functor{delegate_functor{}};
+ entt::delegate invokable_lambda{[value = 2](double v) { return v * value; }};
entt::delegate func_deduced{entt::connect_arg<&delegate_function>};
+ entt::delegate curried_func_by_ref_deduced{entt::connect_arg<&curried_function_by_ref>, 0};
+ entt::delegate curried_func_by_value_deduced{entt::connect_arg<&curried_function_by_value>, 0};
entt::delegate member_f_deduced{entt::connect_arg<&const_nonconst_noexcept::f>, &functor};
entt::delegate member_g_deduced{entt::connect_arg<&const_nonconst_noexcept::g>, &functor};
entt::delegate member_h_deduced{entt::connect_arg<&const_nonconst_noexcept::h>, &functor};
entt::delegate member_i_deduced{entt::connect_arg<&const_nonconst_noexcept::i>, &functor};
+ static_assert(std::is_same_v);
+ static_assert(std::is_same_v);
static_assert(std::is_same_v);
+ static_assert(std::is_same_v);
+ static_assert(std::is_same_v);
static_assert(std::is_same_v);
static_assert(std::is_same_v);
static_assert(std::is_same_v);
static_assert(std::is_same_v);
+ ASSERT_TRUE(invokable_functor);
+ ASSERT_TRUE(invokable_lambda);
ASSERT_TRUE(func_deduced);
+ ASSERT_TRUE(curried_func_by_ref_deduced);
+ ASSERT_TRUE(curried_func_by_value_deduced);
ASSERT_TRUE(member_f_deduced);
ASSERT_TRUE(member_g_deduced);
ASSERT_TRUE(member_h_deduced);
@@ -215,3 +271,30 @@ TEST(Delegate, CurriedFunctionByRef) {
ASSERT_EQ(delegate(), 4);
ASSERT_EQ(delegate(), 8);
}
+
+TEST(Delegate, Constructors) {
+ delegate_functor functor;
+ entt::delegate empty{};
+ entt::delegate invokable{functor};
+ entt::delegate lambda{[value = 5](int v) { return value * v; }};
+ entt::delegate func{entt::connect_arg<&delegate_function>};
+ entt::delegate curr{entt::connect_arg<&curried_function_by_value>, 2};
+ entt::delegate member{entt::connect_arg<&delegate_functor::operator()>, &functor};
+
+ ASSERT_FALSE(empty);
+
+ ASSERT_TRUE(invokable);
+ ASSERT_EQ(6, invokable(3));
+
+ ASSERT_TRUE(lambda);
+ ASSERT_EQ(15, lambda(3));
+
+ ASSERT_TRUE(func);
+ ASSERT_EQ(9, func(3));
+
+ ASSERT_TRUE(curr);
+ ASSERT_EQ(5, curr(3));
+
+ ASSERT_TRUE(member);
+ ASSERT_EQ(6, member(3));
+}
diff --git a/test/entt/signal/dispatcher.cpp b/test/entt/signal/dispatcher.cpp
index 90ed3f905..0965d716f 100644
--- a/test/entt/signal/dispatcher.cpp
+++ b/test/entt/signal/dispatcher.cpp
@@ -15,7 +15,7 @@ TEST(Dispatcher, Functionalities) {
entt::dispatcher dispatcher;
receiver receiver;
- dispatcher.sink().connect(&receiver);
+ dispatcher.sink().connect<&receiver::receive>(&receiver);
dispatcher.trigger(1);
dispatcher.enqueue();
dispatcher.enqueue();
@@ -33,7 +33,7 @@ TEST(Dispatcher, Functionalities) {
an_event event{};
const an_event &cevent = event;
- dispatcher.sink().disconnect(&receiver);
+ dispatcher.sink().disconnect<&receiver::receive>(&receiver);
dispatcher.trigger(an_event{}, 1);
dispatcher.enqueue(event);
dispatcher.update(1);
diff --git a/test/entt/signal/sigh.cpp b/test/entt/signal/sigh.cpp
index 5d561d71d..b35ddca6b 100644
--- a/test/entt/signal/sigh.cpp
+++ b/test/entt/signal/sigh.cpp
@@ -69,54 +69,6 @@ TEST(SigH, Lifetime) {
ASSERT_NO_THROW(delete new signal{});
}
-TEST(SigH, Comparison) {
- entt::sigh sig1;
- entt::sigh sig2;
-
- sigh_listener s1;
- sigh_listener s2;
-
- sig1.sink().connect<&sigh_listener::i>(&s1);
- sig2.sink().connect<&sigh_listener::i>(&s2);
-
- ASSERT_FALSE(sig1 == sig2);
- ASSERT_TRUE(sig1 != sig2);
-
- sig1.sink().disconnect<&sigh_listener::i>(&s1);
- sig2.sink().disconnect<&sigh_listener::i>(&s2);
-
- sig1.sink().connect<&sigh_listener::i>(&s1);
- sig2.sink().connect<&sigh_listener::l>(&s1);
-
- ASSERT_FALSE(sig1 == sig2);
- ASSERT_TRUE(sig1 != sig2);
-
- sig1.sink().disconnect<&sigh_listener::i>(&s1);
- sig2.sink().disconnect<&sigh_listener::l>(&s1);
-
- ASSERT_TRUE(sig1 == sig2);
- ASSERT_FALSE(sig1 != sig2);
-
- sig1.sink().connect<&sigh_listener::i>(&s1);
- sig1.sink().connect<&sigh_listener::l>(&s1);
- sig2.sink().connect<&sigh_listener::i>(&s1);
- sig2.sink().connect<&sigh_listener::l>(&s1);
-
- ASSERT_TRUE(sig1 == sig2);
-
- sig1.sink().disconnect<&sigh_listener::i>(&s1);
- sig1.sink().disconnect<&sigh_listener::l>(&s1);
- sig2.sink().disconnect<&sigh_listener::i>(&s1);
- sig2.sink().disconnect<&sigh_listener::l>(&s1);
-
- sig1.sink().connect<&sigh_listener::i>(&s1);
- sig1.sink().connect<&sigh_listener::l>(&s1);
- sig2.sink().connect<&sigh_listener::l>(&s1);
- sig2.sink().connect<&sigh_listener::i>(&s1);
-
- ASSERT_FALSE(sig1 == sig2);
-}
-
TEST(SigH, Clear) {
entt::sigh sigh;
sigh.sink().connect<&sigh_listener::f>();
@@ -160,7 +112,7 @@ TEST(SigH, Functions) {
ASSERT_TRUE(sigh.empty());
ASSERT_EQ(static_cast::size_type>(0), sigh.size());
- ASSERT_EQ(0, v);
+ ASSERT_EQ(v, 0);
sigh.sink().connect<&sigh_listener::f>();
}
@@ -190,7 +142,8 @@ TEST(SigH, Members) {
ASSERT_FALSE(sigh.empty());
ASSERT_EQ(static_cast::size_type>(2), sigh.size());
- sigh.sink().disconnect(ptr);
+ sigh.sink().disconnect<&sigh_listener::g>(ptr);
+ sigh.sink().disconnect<&sigh_listener::h>(ptr);
ASSERT_TRUE(sigh.empty());
ASSERT_EQ(static_cast::size_type>(0), sigh.size());