boost::capy::any_write_sink

Type‐erased wrapper for any WriteSink.

Synopsis

class any_write_sink;

Description

This class provides type erasure for any type satisfying the WriteSink concept, enabling runtime polymorphism for sink write 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 sink. ‐ Reference: Pass a pointer to wrap without ownership. The pointed‐to sink 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.

Thread Safety

Not thread‐safe. Concurrent operations on the same wrapper are undefined behavior.

Example

// Owning - takes ownership of the sink
any_write_sink ws(some_sink{args...});

// Reference - wraps without ownership
some_sink sink;
any_write_sink ws(&sink);

const_buffer buf(data, size);
auto [ec, n] = co_await ws.write(std::span(&buf, 1));
auto [ec2] = co_await ws.write_eof();

Member Functions

Name

Description

any_write_sink [constructor]

Constructors

~any_write_sink [destructor]

Destructor.

operator= [deleted]

Move assignment operator.

has_value

Check if the wrapper contains a valid sink.

write

write overloads

write_eof

Signal end of data.

operator bool

Check if the wrapper contains a valid sink.

Protected Member Functions

Name

Description

rebind

Rebind to a new sink after move.

See Also

any_write_stream, WriteSink

Created with MrDocs