boost::capy::any_read_source

Type‐erased wrapper for any ReadSource.

Synopsis

class any_read_source;

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

any_read_source [constructor]

Constructors

~any_read_source [destructor]

Destructor.

operator= [deleted]

Move assignment operator.

has_value

Check if the wrapper contains a valid source.

read

Initiate a complete read operation.

read_some

Initiate a partial read operation.

operator bool

Check if the wrapper contains a valid source.

Protected Member Functions

Name

Description

rebind

Rebind to a new source after move.

See Also

any_read_stream, ReadSource

Created with MrDocs