boost::capy::test::bufgrind

Iterates split points of a buffer sequence into two adjacent halves.

Synopsis

template<ConstBufferSequence BS>
class bufgrind;

Description

This class iterates through all possible ways to split a buffer sequence into two parts (b1, b2) where concatenating them yields the original sequence. It uses an async‐generator‐like pattern that allows co_await between iterations.

The split type automatically preserves mutability: passing a MutableBufferSequence yields halves that model MutableBufferSequence, while passing a ConstBufferSequence yields halves that model ConstBufferSequence. Each half is the buffer‐sequence view exposed by a buffer_slice over the corresponding byte range, and can be passed directly to read_some, write_some, buffer_size, etc.

Thread Safety

Not thread‐safe.

Example

// Test all split points of a buffer
std::string data = "hello world";
auto cb = make_buffer( data );

fuse f;
auto r = f.inert( [&]( fuse& ) -> task<> {
    bufgrind bg( cb );
    while( bg ) {
        auto [b1, b2] = co_await bg.next();
        // b1 contains first N bytes (as a buffer sequence)
        // b2 contains remaining bytes (as a buffer sequence)
        // concatenating b1 + b2 equals original
        co_await some_async_operation( b1, b2 );
    }
} );

Mutable Buffer Example

// Mutable buffers preserve mutability
char data[100];
mutable_buffer mb( data, sizeof( data ) );

bufgrind bg( mb );
while( bg ) {
    auto [b1, b2] = co_await bg.next();
    // b1, b2 yield mutable_buffer when iterated
}

Step Size Example

// Skip by 10 bytes for faster iteration
bufgrind bg( cb, 10 );
while( bg ) {
    auto [b1, b2] = co_await bg.next();
    // Visits positions 0, 10, 20, ..., and always size
}

Type Aliases

Name

Description

slice_type

Names the buffer‐sequence type buffer_slice yields for each half.

split_type

Pairs the two slice_type halves that next yields together.

Member Functions

Name

Description

bufgrind [constructor]

Construct a buffer grinder.

next

Return the next split point.

operator bool

Check if more split points remain.

See Also

buffer_slice

Created with MrDocs