1 #ifndef ENTT_SIGNAL_DELEGATE_HPP 2 #define ENTT_SIGNAL_DELEGATE_HPP 34 template<
typename Ret,
typename... Args>
36 using proto_type = Ret(*)(
void *, Args...);
37 using stub_type = std::pair<void *, proto_type>;
39 static Ret fallback(
void *, Args...) noexcept {
return {}; }
41 template<Ret(*Function)(Args...)>
42 static Ret proto(
void *, Args... args) {
43 return (Function)(args...);
46 template<
typename Class, Ret(Class::*Member)(Args...)>
47 static Ret proto(
void *instance, Args... args) {
48 return (static_cast<Class *>(instance)->*Member)(args...);
54 : stub{std::make_pair(
nullptr, &fallback)}
61 template<Ret(*Function)(Args...)>
63 stub = std::make_pair(
nullptr, &proto<Function>);
77 template<
typename Class, Ret(Class::*Member)(Args...)>
79 stub = std::make_pair(instance, &proto<Class, Member>);
88 stub = std::make_pair(
nullptr, &fallback);
97 return stub.second(stub.first, args...);
109 return stub.first == other.stub.first && stub.second == other.stub.second;
128 template<
typename Ret,
typename... Args>
130 return !(lhs == rhs);
137 #endif // ENTT_SIGNAL_DELEGATE_HPP
Delegate() noexcept
Default constructor.
Basic delegate implementation.
bool operator==(const Delegate< Ret(Args...)> &other) const noexcept
Checks if the contents of the two delegates are different.
void connect(Class *instance) noexcept
Connects a member function for a given instance to a delegate.
void connect() noexcept
Binds a free function to a delegate.
Ret operator()(Args... args)
Triggers a delegate.
void reset() noexcept
Resets a delegate.
constexpr bool operator!=(const HashedString &lhs, const HashedString &rhs) noexcept
Compares two hashed strings.