qxLib
qx::delegate< signature_t > Class Template Reference

Single or multicast delegate. More...

#include <delegate.h>

Detailed Description

template<class signature_t>
class qx::delegate< signature_t >

Single or multicast delegate.

For a singlecast version:

  1. Create with qx::delegate<...>::create_singlecast(...);
  2. Call delegate.execute(...).

For a multicast version:

  1. Default construct;
  2. All various callbacks with delegate.add_xxx(...);
  1. Call delegate.execute(...).

If a delegate has only one function inside (i.e. singlecast delegate), it's stored inplace without a container allocation. If a function is small enough (token overload with max 2 bytes captured, object + method pointer overload, weak overload with 1 byte max captured), there will be no allocations at all. The destruction callback overloads require 1 allocation for the alive marker (1 per delegate), because they need to unsubscribe safely.

Template Parameters
signature_t- std::function-like signature of the delegate. For example: void(size_t, const qx::string&). If the result type satisfies qx::delegate_pipe_c, the result of each callable will be piped into the next one, and the final result will be returned by execute(). Otherwise, the result of the last callable will be returned by execute(), and the results of the previous callables will be ignored.
Author
Khrapov
Date
4.07.2025

Definition at line 66 of file delegate.h.


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