On 11/09/2015 10:18 AM, J.Frank wrote:
On Monday, 9 November 2015 at 14:48:35 UTC, Ali Çehreli wrote:
import std.stdio;
import std.range;

void foo(I, O)(I in_stream, O out_stream)
        if (isInputRange!I &&
            isOutputRange!(O, ElementType!I)) {

    // in_stream.seek(3); // compile error - good :)

    foreach (element; in_stream) {
        out_stream.put(element);
    }
}

void main(string[] args)
{
    // Also consider .byLine, which is faster and risky
    foo(stdin.byLineCopy,
        stdout.lockingTextWriter);
}

Ali

Uhm... no. That's not a solution to my problem. Ranges are not
(I/O-)streams.


As far as I understand, the issue is to prevent the seek() call at compile time, right? If so, the range types that byLine() and byLineCopy() return does not have such a member function.

I think the code achieves that goal because we are not dealing with File objects anymore.

Ali

Reply via email to