|
|
@@ -116,8 +116,8 @@ public:
|
|
|
|
|
|
/*! @brief Default constructor. */
|
|
|
delegate() ENTT_NOEXCEPT
|
|
|
- : fn{nullptr},
|
|
|
- data{nullptr} {}
|
|
|
+ : instance{nullptr},
|
|
|
+ fn{nullptr} {}
|
|
|
|
|
|
/**
|
|
|
* @brief Constructs a delegate and connects a free function or an unbound
|
|
|
@@ -157,7 +157,7 @@ public:
|
|
|
*/
|
|
|
template<auto Candidate>
|
|
|
void connect() ENTT_NOEXCEPT {
|
|
|
- data = nullptr;
|
|
|
+ instance = nullptr;
|
|
|
|
|
|
if constexpr(std::is_invocable_r_v<Ret, decltype(Candidate), Args...>) {
|
|
|
fn = [](const void *, Args... args) -> Ret {
|
|
|
@@ -187,7 +187,7 @@ public:
|
|
|
*/
|
|
|
template<auto Candidate, typename Type>
|
|
|
void connect(Type &value_or_instance) ENTT_NOEXCEPT {
|
|
|
- data = &value_or_instance;
|
|
|
+ instance = &value_or_instance;
|
|
|
|
|
|
if constexpr(std::is_invocable_r_v<Ret, decltype(Candidate), Type &, Args...>) {
|
|
|
fn = [](const void *payload, Args... args) -> Ret {
|
|
|
@@ -211,7 +211,7 @@ public:
|
|
|
*/
|
|
|
template<auto Candidate, typename Type>
|
|
|
void connect(Type *value_or_instance) ENTT_NOEXCEPT {
|
|
|
- data = value_or_instance;
|
|
|
+ instance = value_or_instance;
|
|
|
|
|
|
if constexpr(std::is_invocable_r_v<Ret, decltype(Candidate), Type *, Args...>) {
|
|
|
fn = [](const void *payload, Args... args) -> Ret {
|
|
|
@@ -237,8 +237,8 @@ public:
|
|
|
* @param payload User defined arbitrary data.
|
|
|
*/
|
|
|
void connect(function_type *function, const void *payload = nullptr) ENTT_NOEXCEPT {
|
|
|
+ instance = payload;
|
|
|
fn = function;
|
|
|
- data = payload;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -247,16 +247,16 @@ public:
|
|
|
* After a reset, a delegate cannot be invoked anymore.
|
|
|
*/
|
|
|
void reset() ENTT_NOEXCEPT {
|
|
|
+ instance = nullptr;
|
|
|
fn = nullptr;
|
|
|
- data = nullptr;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @brief Returns the instance or the payload linked to a delegate, if any.
|
|
|
* @return An opaque pointer to the underlying data.
|
|
|
*/
|
|
|
- [[nodiscard]] const void *instance() const ENTT_NOEXCEPT {
|
|
|
- return data;
|
|
|
+ [[nodiscard]] const void *data() const ENTT_NOEXCEPT {
|
|
|
+ return instance;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -273,7 +273,7 @@ public:
|
|
|
*/
|
|
|
Ret operator()(Args... args) const {
|
|
|
ENTT_ASSERT(static_cast<bool>(*this), "Uninitialized delegate");
|
|
|
- return fn(data, std::forward<Args>(args)...);
|
|
|
+ return fn(instance, std::forward<Args>(args)...);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -281,7 +281,7 @@ public:
|
|
|
* @return False if the delegate is empty, true otherwise.
|
|
|
*/
|
|
|
[[nodiscard]] explicit operator bool() const ENTT_NOEXCEPT {
|
|
|
- // no need to test also data
|
|
|
+ // no need to also test instance
|
|
|
return !(fn == nullptr);
|
|
|
}
|
|
|
|
|
|
@@ -291,12 +291,12 @@ public:
|
|
|
* @return False if the two contents differ, true otherwise.
|
|
|
*/
|
|
|
[[nodiscard]] bool operator==(const delegate<Ret(Args...)> &other) const ENTT_NOEXCEPT {
|
|
|
- return fn == other.fn && data == other.data;
|
|
|
+ return fn == other.fn && instance == other.instance;
|
|
|
}
|
|
|
|
|
|
private:
|
|
|
+ const void *instance;
|
|
|
function_type *fn;
|
|
|
- const void *data;
|
|
|
};
|
|
|
|
|
|
/**
|