boost::capy::any_executor

A type‐erased wrapper for executor objects.

Synopsis

class any_executor;

Description

This class provides type erasure for any executor type, enabling runtime polymorphism with automatic memory management via shared ownership. It stores a shared pointer to a polymorphic wrapper, allowing executors of different types to be stored uniformly while satisfying the full Executor concept.

Value Semantics

This class has value semantics with shared ownership. Copy and move operations are cheap, simply copying the internal shared pointer. Multiple any_executor instances may share the same underlying executor. Move operations do not invalidate the source; there is no moved‐from state.

Default State

A default‐constructed any_executor holds no executor. Calling executor operations on a default‐constructed instance results in undefined behavior. Use operator bool() to check validity.

Thread Safety

The any_executor itself is thread‐safe for concurrent reads. Concurrent modification requires external synchronization. Executor operations are safe to call concurrently if the underlying executor supports it.

Executor Concept

This class satisfies the Executor concept, making it usable anywhere a concrete executor is expected.

Example

any_executor exec = ctx.get_executor();
if(exec)
{
    auto& context = exec.context();
    exec.post(my_coroutine);
}

Member Functions

Name

Description

any_executor [constructor]

Constructors

operator=

Copy assignment operator.

context

Returns a reference to the associated execution context.

dispatch

Dispatches a coroutine handle through the wrapped executor.

on_work_finished

Informs the executor that work has completed.

on_work_started

Informs the executor that work is beginning.

post

Posts a coroutine handle to the wrapped executor.

target_type

Returns the type_info of the wrapped executor.

operator bool

Returns true if this instance holds a valid executor.

operator==

Compares two executor wrappers for equality.

See Also

executor_ref, Executor

Created with MrDocs