EnTT: entt::delegate< Ret(Args...)> Class Template Reference

EnTT 3.16.0

Loading...
Searching...
No Matches
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 <delegate.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 () noexcept=default
| Default constructor.
template<auto Candidate, typename... Type>
| delegate (connect_arg_t< Candidate >, Type &&...value_or_instance) noexcept
| Constructs a delegate with a given object or payload, if any.
| delegate (function_type *function, const void *payload=nullptr) noexcept
| Constructs a delegate and connects an user defined function with optional payload.
template<auto Candidate>
void | connect () noexcept
| Connects a free function or an unbound member to a delegate.
template<auto Candidate, typename Type>
void | connect (Type &value_or_instance) noexcept
| Connects a free function with payload or a bound member to a delegate.
template<auto Candidate, typename Type>
void | connect (Type *value_or_instance) noexcept
| Connects a free function with payload or a bound member to a delegate.
void | connect (function_type *function, const void *payload=nullptr) noexcept
| Connects an user defined function with optional payload to a delegate.
void | reset () noexcept
| Resets a delegate.
function_type * | target () const noexcept
| Returns a pointer to the stored callable function target, if any.
const void * | data () const noexcept
| Returns the instance or the payload linked to a delegate, if any.
Ret | operator() (Args... args) const
| Triggers a delegate.
| operator bool () const noexcept
| Checks whether a delegate actually stores a listener.
bool | operator== (const delegate< Ret(Args...)> &other) const noexcept
| Compares the contents of two delegates.

## 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

  Ret | Return type of a function type.
  Args | Types of arguments of a function type.

Definition at line 66 of file delegate.hpp.

## Member Typedef Documentation

## ◆ function_type

template<typename Ret, typename... Args>

using entt::delegate< Ret(Args...)>::function_type = Ret(const void *, Args...)

Function type of the contained target.

Definition at line 101 of file delegate.hpp.

## ◆ result_type

template<typename Ret, typename... Args>

using entt::delegate< Ret(Args...)>::result_type = Ret

Return type of the delegate.

Definition at line 105 of file delegate.hpp.

## ◆ type

template<typename Ret, typename... Args>

using entt::delegate< Ret(Args...)>::type = Ret(Args...)

Function type of the delegate.

Definition at line 103 of file delegate.hpp.

## Constructor & Destructor Documentation

## ◆ delegate() [1/2]

template<typename Ret, typename... Args>
template<auto Candidate, typename... Type>

entt::delegate< Ret(Args...)>::delegate | ( | connect_arg_t< Candidate > | ,
|  | Type &&... | value_or_instance )
| inlinenoexcept

Constructs a delegate with a given object or payload, if any.

Template Parameters

  Candidate | Function or member to connect to the delegate.
  Type | Type of class or type of payload, if any.

Parameters

  value_or_instance | Optional valid object that fits the purpose.

Definition at line 117 of file delegate.hpp.

## ◆ delegate() [2/2]

template<typename Ret, typename... Args>

entt::delegate< Ret(Args...)>::delegate | ( | function_type * | function,
|  | const void * | payload = nullptr )
| inlinenoexcept

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

Parameters

  function | Function to connect to the delegate.
  payload | User defined arbitrary data.

Definition at line 127 of file delegate.hpp.

## Member Function Documentation

## ◆ connect() [1/4]

template<typename Ret, typename... Args>
template<auto Candidate>

void entt::delegate< Ret(Args...)>::connect | ( |  | ) |
| inlinenoexcept

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

Template Parameters

  Candidate | Function or member to connect to the delegate.

Definition at line 136 of file delegate.hpp.

## ◆ connect() [2/4]

template<typename Ret, typename... Args>

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

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

  function | Function to connect to the delegate.
  payload | User defined arbitrary data.

Definition at line 216 of file delegate.hpp.

## ◆ connect() [3/4]

template<typename Ret, typename... Args>
template<auto Candidate, typename Type>

void entt::delegate< Ret(Args...)>::connect | ( | Type & | value_or_instance | ) |
| inlinenoexcept

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

  Candidate | Function or member to connect to the delegate.
  Type | Type of class or type of payload.

Parameters

  value_or_instance | A valid reference that fits the purpose.

Definition at line 166 of file delegate.hpp.

## ◆ connect() [4/4]

template<typename Ret, typename... Args>
template<auto Candidate, typename Type>

void entt::delegate< Ret(Args...)>::connect | ( | Type * | value_or_instance | ) |
| inlinenoexcept

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

See also
  connect(Type &)

Template Parameters

  Candidate | Function or member to connect to the delegate.
  Type | Type of class or type of payload.

Parameters

  value_or_instance | A valid pointer that fits the purpose.

Definition at line 190 of file delegate.hpp.

## ◆ data()

template<typename Ret, typename... Args>

const void * entt::delegate< Ret(Args...)>::data | ( |  | ) | const
| inlinenodiscardnoexcept

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

Returns
  An opaque pointer to the underlying data.

Definition at line 244 of file delegate.hpp.

## ◆ operator bool()

template<typename Ret, typename... Args>

entt::delegate< Ret(Args...)>::operator bool | ( |  | ) | const
| inlineexplicitnodiscardnoexcept

Checks whether a delegate actually stores a listener.

Returns
  False if the delegate is empty, true otherwise.

Definition at line 269 of file delegate.hpp.

## ◆ 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

  args | Arguments to use to invoke the underlying function.

Returns
  The value returned by the underlying function.

Definition at line 260 of file delegate.hpp.

## ◆ operator==()

template<typename Ret, typename... Args>

bool entt::delegate< Ret(Args...)>::operator== | ( | const delegate< Ret(Args...)> & | other | ) | const
| inlinenodiscardnoexcept

Compares the contents of two delegates.

Parameters

  other | Delegate with which to compare.

Returns
  False if the two contents differ, true otherwise.

Definition at line 279 of file delegate.hpp.

## ◆ reset()

template<typename Ret, typename... Args>

void entt::delegate< Ret(Args...)>::reset | ( |  | ) |
| inlinenoexcept

Resets a delegate.

After a reset, a delegate cannot be invoked anymore.

Definition at line 227 of file delegate.hpp.

## ◆ target()

template<typename Ret, typename... Args>

function_type * entt::delegate< Ret(Args...)>::target | ( |  | ) | const
| inlinenodiscardnoexcept

Returns a pointer to the stored callable function target, if any.

Returns
  An opaque pointer to the stored callable function target.

Definition at line 236 of file delegate.hpp.

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

- src/entt/signal/delegate.hpp