Idiomatic way to write a range that tracks how much it consumes

anon anon at noreply.com
Mon Apr 27 05:06:21 UTC 2020


To implement your option A you could simply use 
std.range.enumerate.

Would something like this work?

import std.algorithm.iteration : map;
import std.algorithm.searching : until;
import std.range : tee;

size_t bytesConsumed;
auto result = input.map!(a => a.yourTransformation )
                    .until!(stringTerminator)
                    .tee!(a => bytesConsumed++);
// bytesConsumed is automatically updated as result is consumed


More information about the Digitalmars-d-learn mailing list