diff --git a/src/entt/signal/sigh.hpp b/src/entt/signal/sigh.hpp index ffd220dd3..bdbb9d30d 100644 --- a/src/entt/signal/sigh.hpp +++ b/src/entt/signal/sigh.hpp @@ -476,81 +476,47 @@ public: } /** - * @brief Connects a free function or an unbound member to a signal. + * @brief Connects a free function (with or without payload), a bound or an + * unbound member to a signal. * - * The signal handler performs checks to avoid multiple connections for the - * same function. - * - * @tparam Candidate Function or member to connect to the signal. - * @return A properly initialized connection object. - */ - template - connection connect() { - disconnect(); - - delegate call{}; - call.template connect(); - signal->calls.insert(signal->calls.end() - offset, std::move(call)); - - delegate conn{}; - conn.template connect<&release>(); - return {std::move(conn), signal}; - } - - /** - * @brief Connects a free function with payload or a bound member to a - * signal. - * - * The signal isn't responsible for the connected object or the payload. - * Users must always guarantee that the lifetime of the instance overcomes - * the one of the signal. On the other side, the signal handler performs + * The signal isn't responsible for the connected object or the payload, if + * any. 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 function.
* When used to connect a free function with payload, its signature must be * such that the instance is the first argument before the ones used to * define the signal itself. * * @tparam Candidate Function or member to connect to the signal. - * @tparam Type Type of class or type of payload. - * @param value_or_instance A valid object that fits the purpose. + * @tparam Type Type of class or type of payload, if any. + * @param value_or_instance A valid object that fits the purpose, if any. * @return A properly initialized connection object. */ - template - connection connect(Type &&value_or_instance) { - disconnect(value_or_instance); + template + connection connect(Type &&...value_or_instance) { + disconnect(value_or_instance...); delegate call{}; - call.template connect(value_or_instance); + call.template connect(value_or_instance...); signal->calls.insert(signal->calls.end() - offset, std::move(call)); delegate conn{}; - conn.template connect<&release>(value_or_instance); + conn.template connect<&release>(value_or_instance...); return {std::move(conn), signal}; } /** - * @brief Disconnects a free function or an unbound member from a signal. + * @brief Disconnects a free function (with or without payload), a bound or + * an unbound member from a signal. * @tparam Candidate Function or member to disconnect from the signal. + * @tparam Type Type of class or type of payload, if any. + * @param value_or_instance A valid object that fits the purpose, if any. */ - template - void disconnect() { + template + void disconnect(Type &&...value_or_instance) { auto &calls = signal->calls; delegate call{}; - call.template connect(); - calls.erase(std::remove(calls.begin(), calls.end(), std::move(call)), calls.end()); - } - - /** - * @brief Disconnects a free function with payload or a bound member from a - * signal. - * @tparam Candidate Function or member to disconnect from the 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) { - auto &calls = signal->calls; - delegate call{}; - call.template connect(value_or_instance); + call.template connect(value_or_instance...); calls.erase(std::remove(calls.begin(), calls.end(), std::move(call)), calls.end()); }