boost::capy::any_read_source
Type‐erased wrapper for any ReadSource.
Description
This class provides type erasure for any type satisfying the ReadSource concept, enabling runtime polymorphism for source read operations. It uses cached awaitable storage to achieve zero steady‐state allocation after construction.
The wrapper supports two construction modes: ‐ Owning: Pass by value to transfer ownership. The wrapper allocates storage and owns the source. ‐ Reference: Pass a pointer to wrap without ownership. The pointed‐to source must outlive this wrapper.
Awaitable Preallocation
The constructor preallocates storage for the type‐erased awaitable. This reserves all virtual address space at server startup so memory usage can be measured up front, rather than allocating piecemeal as traffic arrives.
Immediate Completion
Operations complete immediately without suspending when the buffer sequence is empty, or when the underlying source's awaitable reports readiness via await_ready.
Thread Safety
Not thread‐safe. Concurrent operations on the same wrapper are undefined behavior.
Example
// Owning - takes ownership of the source
any_read_source rs(some_source{args...});
// Reference - wraps without ownership
some_source source;
any_read_source rs(&source);
mutable_buffer buf(data, size);
auto [ec, n] = co_await rs.read(std::span(&buf, 1));
Member Functions
Name |
Description |
|
Constructors |
|
Destructor. |
|
Move assignment operator. |
Check if the wrapper contains a valid source. |
|
Initiate a complete read operation. |
|
Initiate a partial read operation. |
|
Check if the wrapper contains a valid source. |
See Also
any_read_stream, ReadSource
Created with MrDocs