boost::capy::any_dispatcher
A type‐erased wrapper for dispatcher objects.
Synopsis
Declared in <boost/capy/any_dispatcher.hpp>
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 |
|
Constructors |
Copy assignment operator. |
|
Dispatches a coroutine handle through the wrapped dispatcher. |
|
Returns true if this instance holds a valid dispatcher. |
|
Compares two dispatchers for identity. |