Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

dynamic_buffer_ref

Return a non-owning reference to a dynamic buffer.

Synopsis

Defined in header <boost/beast/core/dynamic_buffer_ref.hpp>

template<
    class DynamicBuffer>
dynamic_buffer_ref_wrapper< DynamicBuffer >
dynamic_buffer_ref(
    DynamicBuffer& buffer);
Description

This function returns a wrapper which holds a reference to the passed dynamic buffer. The wrapper meets the requirements of DynamicBuffer, allowing its use in Networking algorithms which want to take ownership of the dynamic buffer. Since Beast dynamic buffers are true storage types, they cannot be used directly with functions that take ownership of the dynamic buffer.

Example

This function reads a line of text from a stream into a basic_flat_buffer, using the net function async_read_until.

template <class SyncReadStream>
std::size_t read_line (SyncReadStream& stream, flat_buffer& buffer)
{
    return net::read_until(stream, dynamic_buffer_ref(buffer), "\r\n");
}
Parameters

Name

Description

buffer

The dynamic buffer to wrap. Ownership of the buffer is not transferred, the caller is still responsible for managing the lifetime of the original object.

Return Value

A wrapper meeting the requirements of DynamicBuffer which references the original dynamic buffer.

See Also

dynamic_buffer_ref_wrapper

Convenience header <boost/beast/core.hpp>


PrevUpHomeNext