On Saturday, 7 November 2015 at 13:52:29 UTC, Spacen Jasset wrote:
[...]
I have a used a template, because I cannot directly use the InputRange(char) interface as a type, and auto won't work either, so is there another parameter type I can use, such that I can have the concept of an abstract stream of bytes.

With the help of a template constraint you can abstract this. It looks like your problem is more getting the whole range since .byLine or .byChunk don't return the full stuff. Maybe use std.alsorithm.joiner. As you noted you can carry the iterator without knowing the type with auto, example:

---
import std.stdio;
import std.range, std.algorithm;

void main(string[] args)
{
    auto inputRange = File(__FILE__).byChunk(1024).joiner;
    Foo foo = Foo(inputRange);
}

struct Foo
{
    this(T)(T t)
    if (isInputRange!T && is(ElementType!T == ubyte))
    {
        foreach(byte b; t)
        {
            writef("0x%.2X ", b);
            if (b == 0xA) writeln;
        }
    }
}
---


Reply via email to