On 2010-01-29 11:18:46 -0500, Andrei Alexandrescu <seewebsiteforem...@erdani.org> said:

It should work for stream ranges if front() checks the "filled" flag and eats the next line if false, and popFront clears the "filled" flag.

So now you want the front to fetch from stdin on the first call? It's the same problem as 'byLine' eating the first line when you create it: neither one or the other should affect the stream.

Take my example from before:

        // fetch 3 lines:
        string[] consume(3, stdin.byLine);
        // now fill a buffer
        ubyte[] buffer;
        buffer = stdin.rawRead(buffer);

        E[] consume(E, R)(int count, R range) {
                E[] elements;
                foreach (i; 0..count) {
                        elements ~= range.front;
                        range.popFront();
                }
                return elements;
        }

Now add a range.front just after the popFront():

        E[] consume(E, R)(int count, R range) {
                E[] elements;
                foreach (i; 0..count) {
                        elements ~= range.front;
                        range.popFront();
                        E peakedElement = range.front;
                }
                return elements;
        }

And suddenly you'll get the same problem.

--
Michel Fortin
michel.for...@michelf.com
http://michelf.com/

Reply via email to