istream_iterator

Posted on Fri 18 June 2021 in tech

Although c++ is already imbued with the kitchen sink, it seems to lack a chunked character iterator for input streams.

Here is a little repository to implement that: Block Iterator

An example looks like any istream iterator idiom:

constexpr auto N = 3;
const auto example = "AAABBBCCC";
std::istringstream ss(example);
std::vector<std::string> blocks{};
std::copy(istream_block_iterator<std::string>(ss, N), istream_block_iterator<std::string>(),std::back_inserter(blocks));

But the result is vector blocks with maximum N characters per string.