boost::capy::any_dispatcher

A type‐erased wrapper for dispatcher objects.

Synopsis

class any_dispatcher;

Description

This class provides type erasure for any type satisfying the dispatcher concept, enabling runtime polymorphism without virtual functions. It stores a pointer to the original dispatcher and a function pointer to invoke it, allowing dispatchers of different types to be stored uniformly.

Thread Safety

The any_dispatcher itself is not thread‐safe for concurrent modification, but operator() is const and safe to call concurrently if the underlying dispatcher supports concurrent dispatch.

Lifetime

The any_dispatcher stores a pointer to the original dispatcher object. The caller must ensure the referenced dispatcher outlives the any_dispatcher instance. This is typically satisfied when the dispatcher is an executor stored in a coroutine promise or service provider.

Example

void store_dispatcher(any_dispatcher d)
{
    // Can store any dispatcher type uniformly
    auto h = d(some_coroutine);  // Invoke through type-erased interface
}

executor_base const& ex = get_executor();
store_dispatcher(ex);  // Implicitly converts to any_dispatcher

Member Functions

Name

Description

any_dispatcher [constructor]

Constructors

operator=

Copy assignment operator.

operator()

Dispatches a coroutine handle through the wrapped dispatcher.

operator bool

Returns true if this instance holds a valid dispatcher.

operator==

Compares two dispatchers for identity.

See Also

dispatcher

executor_base

Created with MrDocs