On Saturday, 26 March 2016 at 08:34:04 UTC, cym13 wrote:

Sorry, it seems I completely misunderstood you goal. I thought that take() consumed its input (which mostly only shows that I really am careful about not reusing ranges). Writting a take that consume shouldn't be difficult though:

    import std.range, std.traits;
    Take!R takeConsume(R)(auto ref R input, size_t n)
        if (isInputRange!(Unqual!R)
        && !isInfinite!(Unqual!R)
    {
        auto buffer = input.take(n);
        input = input.drop(buffer.walkLength);
        return buffer;
    }

but I think going with std.bitmanip/read may be the easiest in the end.

Turns out bitmanip is actually using a loop.

foreach(ref e; bytes)
{
  e = range.front;
  range.popFront();
}

By the way, in your code above you are actually reusing the range: take is followed by drop and it won't work on an input range like 'byChunk'. That's the problem I ran into (see first post).

Reply via email to