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

anon anon at
Mon Apr 27 05:06:21 UTC 2020

To implement your option A you could simply use 

Would something like this work?

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

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

More information about the Digitalmars-d-learn mailing list