boost::capy::executor_ref

A type‐erased reference wrapper for executor objects.

Synopsis

class executor_ref;

Description

This class provides type erasure for any executor type, enabling runtime polymorphism without virtual functions or allocation. It stores a pointer to the original executor and a pointer to a static vtable, allowing executors of different types to be stored uniformly while satisfying the full Executor concept.

Reference Semantics

This class has reference semantics: it does not allocate or own the wrapped executor. Copy operations simply copy the internal pointers. The caller must ensure the referenced executor outlives all executor_ref instances that wrap it.

Thread Safety

The executor_ref itself is not thread‐safe for concurrent modification, but its 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

void store_executor(executor_ref ex)
{
    if(ex)
        ex.post(my_coroutine);
}

io_context ctx;
store_executor(ctx.get_executor());

Member Functions

Name

Description

executor_ref [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

Return a pointer to the wrapped executor if it matches the requested type.

operator bool

Returns true if this instance holds a valid executor.

operator==

Compares two executor references for equality.

See Also

any_executor, Executor

Created with MrDocs