Engine → Core → delegate.h
delegate
| Type | Class |
| Namespace | conjure::core |
| Include File Path | engine/include/conjure/core/delegate.h |
| Source File Path | N/A |
| API ↗ | Time, events and random |
Syntax
Constructors
| Access | Signature | Description |
|---|---|---|
| public | constexpr delegate() noexcept = default; |
Variables
| Access | Name | Type | Default | Description |
|---|---|---|---|---|
| public | CAN_BIND | template < | sizeof(Callable) < | True when a callable type can be bound: trivially copyable, pointer-aligned, fits the inline storage and is invocable as const with the delegate's signature. |
| private | mInvoke | invoker_type | nullptr | |
| public | STORAGE_ | static constexpr usize | 2 * sizeof(void *) | Bytes of inline storage for the bound target. |
| private | void | alignas( *) std:: | {} |
Functions
Public
bind
bindtemplate <auto Function> requires std::is_pointer_v<decltype(Function)> && std::is_function_v<std::remove_pointer_t<decltype(Function)>> && std::is_invocable_r_v<Return, decltype(Function), Args...> [[nodiscard]] static delegate bind() noexcept;Binds a free function known at compile time.
template <auto Method, typename Class> requires std::is_member_function_pointer_v<decltype(Method)> && std::is_invocable_r_v<Return, decltype(Method), Class *, Args...> [[nodiscard]] static delegate bind(
Class *instance) noexcept;Binds a member function to an instance: delegate<void(int)>::bind<&foo::bar>(&foo). Const member functions accept a pointer to const. The instance is not owned.
[[nodiscard]] static delegate bind(
function_pointer function) noexcept;Binds a function pointer chosen at runtime. A null pointer yields an unbound delegate.
template <typename Callable> requires (!std::is_same_v<std::remove_cvref_t<Callable>, delegate>) && (!std::is_same_v<std::remove_cvref_t<Callable>, function_pointer>) [[nodiscard]] static delegate bind(
Callable callable) noexcept;Binds a stateless or small trivially copyable callable (see CAN_BIND) by copying it into the inline storage.
is_bound
is_bound[[nodiscard]] constexpr bool is_bound() const noexcept;True when a target is bound.
reset
resetconstexpr void reset() noexcept;Unbinds the delegate.
Private
invoke_callable
invoke_callabletemplate <typename Callable> static Return invoke_callable(
const void *storage,
Args... args);invoke_function_pointer
invoke_function_pointerstatic Return invoke_function_pointer(
const void *storage,
Args... args);invoke_member
invoke_membertemplate <auto Method, typename Class> static Return invoke_member(
const void *storage,
Args... args);invoke_static
invoke_statictemplate <auto Function> static Return invoke_static(
[[maybe_unused]] const void *storage,
Args... args);Operator Overloads
Public
operator bool
operator bool[[nodiscard]] constexpr explicit operator bool() const noexcept;Same as is_bound().
operator()
operator()Return operator()(
Args... args) const;Invokes the bound target. Calling an unbound delegate asserts and returns a default-constructed value (or nothing for void).
operator==
operator==[[nodiscard]] bool operator==(
const delegate &other) const noexcept;Two delegates are equal when they invoke the same target on the same instance (or the same captured state). Unbound delegates are equal to each other. The comparison is of the invoker and the raw inline storage, which is exact for free-function, member, function-pointer and stateless-lambda bindings. A capturing lambda is copied whole, padding included, so its equality is exact only when the closure has no padding (std::has_unique_object_representations_v); otherwise two bindings with equal captures (a bool next to a pointer, say) may compare unequal.