Clementine
Public Types | Public Member Functions | List of all members
entt::delegate< Ret(Args...)> Class Template Reference

Utility class to use to send around functions and members. More...

#include <entt.hpp>

Public Types

using function_type = Ret(const void *, Args...)
 Function type of the contained target.
 
using type = Ret(Args...)
 Function type of the delegate.
 
using result_type = Ret
 Return type of the delegate.
 

Public Member Functions

 delegate () ENTT_NOEXCEPT
 Default constructor.
 
template<auto Candidate>
 delegate (connect_arg_t< Candidate >) ENTT_NOEXCEPT
 Constructs a delegate and connects a free function or an unbound member. More...
 
template<auto Candidate, typename Type >
 delegate (connect_arg_t< Candidate >, Type &&value_or_instance) ENTT_NOEXCEPT
 Constructs a delegate and connects a free function with payload or a bound member. More...
 
 delegate (function_type *function, const void *payload=nullptr) ENTT_NOEXCEPT
 Constructs a delegate and connects an user defined function with optional payload. More...
 
template<auto Candidate>
void connect () ENTT_NOEXCEPT
 Connects a free function or an unbound member to a delegate. More...
 
template<auto Candidate, typename Type >
void connect (Type &value_or_instance) ENTT_NOEXCEPT
 Connects a free function with payload or a bound member to a delegate. More...
 
template<auto Candidate, typename Type >
void connect (Type *value_or_instance) ENTT_NOEXCEPT
 Connects a free function with payload or a bound member to a delegate. More...
 
void connect (function_type *function, const void *payload=nullptr) ENTT_NOEXCEPT
 Connects an user defined function with optional payload to a delegate. More...
 
void reset () ENTT_NOEXCEPT
 Resets a delegate. More...
 
const void * instance () const ENTT_NOEXCEPT
 Returns the instance or the payload linked to a delegate, if any. More...
 
Ret operator() (Args... args) const
 Triggers a delegate. More...
 
 operator bool () const ENTT_NOEXCEPT
 Checks whether a delegate actually stores a listener. More...
 
bool operator== (const delegate< Ret(Args...)> &other) const ENTT_NOEXCEPT
 Compares the contents of two delegates. More...
 

Detailed Description

template<typename Ret, typename... Args>
class entt::delegate< Ret(Args...)>

Utility class to use to send around functions and members.

Unmanaged delegate for function pointers and members. Users of this class are in charge of disconnecting instances before deleting them.

A delegate can be used as a general purpose invoker without memory overhead for free functions possibly with payloads and bound or unbound members.

Template Parameters
RetReturn type of a function type.
ArgsTypes of arguments of a function type.

Constructor & Destructor Documentation

◆ delegate() [1/3]

template<typename Ret , typename... Args>
template<auto Candidate>
entt::delegate< Ret(Args...)>::delegate ( connect_arg_t< Candidate >  )
inline

Constructs a delegate and connects a free function or an unbound member.

Template Parameters
CandidateFunction or member to connect to the delegate.

◆ delegate() [2/3]

template<typename Ret , typename... Args>
template<auto Candidate, typename Type >
entt::delegate< Ret(Args...)>::delegate ( connect_arg_t< Candidate >  ,
Type &&  value_or_instance 
)
inline

Constructs a delegate and connects a free function with payload or a bound member.

Template Parameters
CandidateFunction or member to connect to the delegate.
TypeType of class or type of payload.
Parameters
value_or_instanceA valid object that fits the purpose.

◆ delegate() [3/3]

template<typename Ret , typename... Args>
entt::delegate< Ret(Args...)>::delegate ( function_type function,
const void *  payload = nullptr 
)
inline

Constructs a delegate and connects an user defined function with optional payload.

Parameters
functionFunction to connect to the delegate.
payloadUser defined arbitrary data.

Member Function Documentation

◆ connect() [1/4]

template<typename Ret , typename... Args>
template<auto Candidate>
void entt::delegate< Ret(Args...)>::connect ( )
inline

Connects a free function or an unbound member to a delegate.

Template Parameters
CandidateFunction or member to connect to the delegate.

◆ connect() [2/4]

template<typename Ret , typename... Args>
template<auto Candidate, typename Type >
void entt::delegate< Ret(Args...)>::connect ( Type &  value_or_instance)
inline

Connects a free function with payload or a bound member to a delegate.

The delegate 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 delegate.
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 delegate itself.

Template Parameters
CandidateFunction or member to connect to the delegate.
TypeType of class or type of payload.
Parameters
value_or_instanceA valid reference that fits the purpose.

◆ connect() [3/4]

template<typename Ret , typename... Args>
template<auto Candidate, typename Type >
void entt::delegate< Ret(Args...)>::connect ( Type *  value_or_instance)
inline

Connects a free function with payload or a bound member to a delegate.

See also
connect(Type &)
Template Parameters
CandidateFunction or member to connect to the delegate.
TypeType of class or type of payload.
Parameters
value_or_instanceA valid pointer that fits the purpose.

◆ connect() [4/4]

template<typename Ret , typename... Args>
void entt::delegate< Ret(Args...)>::connect ( function_type function,
const void *  payload = nullptr 
)
inline

Connects an user defined function with optional payload to a delegate.

The delegate isn't responsible for the connected object or the payload. Users must always guarantee that the lifetime of an instance overcomes the one of the delegate.
The payload is returned as the first argument to the target function in all cases.

Parameters
functionFunction to connect to the delegate.
payloadUser defined arbitrary data.

◆ instance()

template<typename Ret , typename... Args>
const void* entt::delegate< Ret(Args...)>::instance ( ) const
inline

Returns the instance or the payload linked to a delegate, if any.

Returns
An opaque pointer to the underlying data.

◆ operator bool()

template<typename Ret , typename... Args>
entt::delegate< Ret(Args...)>::operator bool ( ) const
inlineexplicit

Checks whether a delegate actually stores a listener.

Returns
False if the delegate is empty, true otherwise.

◆ operator()()

template<typename Ret , typename... Args>
Ret entt::delegate< Ret(Args...)>::operator() ( Args...  args) const
inline

Triggers a delegate.

The delegate invokes the underlying function and returns the result.

Warning
Attempting to trigger an invalid delegate results in undefined behavior.
Parameters
argsArguments to use to invoke the underlying function.
Returns
The value returned by the underlying function.

◆ operator==()

template<typename Ret , typename... Args>
bool entt::delegate< Ret(Args...)>::operator== ( const delegate< Ret(Args...)> &  other) const
inline

Compares the contents of two delegates.

Parameters
otherDelegate with which to compare.
Returns
False if the two contents differ, true otherwise.

◆ reset()

template<typename Ret , typename... Args>
void entt::delegate< Ret(Args...)>::reset ( )
inline

Resets a delegate.

After a reset, a delegate cannot be invoked anymore.


The documentation for this class was generated from the following file: