MutableBufferSequence

A mutable buffer sequence represents zero or more contiguous memory regions as a bidirectional range whose value type is convertible to mutable_buffer, or as an object which is convertible to mutable_buffer. All mutable buffer sequences are also constant buffer sequences.

template< typename T >
concept mutable_buffer_sequence =
    std::is_convertible_v<T, mutable_buffer> || (
        std::ranges::bidirectional_range<T> &&
        std::is_convertible_v<std::ranges::range_value_t<T>, mutable_buffer>);

While the functions std::ranges::begin and std::ranges::end will work on bidirectional ranges, they do not handle objects which are merely convertible to mutable_buffer. To enable this use-case, the functions buffers::begin and buffers::end must be used. These are always called with namespace qualification. Alternatively, the function buffers::single or std::views::single may be used to adapt a mutable_buffer into a 1-element range.

Copies of a buffer sequence must point to the same memory regions:

T t(u);
static_assert( mutable_buffer_sequence<T> );
assert( std::equal(
    buffers::begin(t), buffers::end(t),
    buffers::begin(u), buffers::end(u),
    [](mutable_buffer const& b1, mutable_buffer const& b2)
    {
        return b1.data() == b2.data() && b1.size() == b2.size();
    }));

Models