stdio.lines doesn't have popFront, but works with foreach

Andrew Klaassen via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Dec 11 12:11:20 PST 2014


The docs for stdio.lines say that it's a struct.  stdio.lines 
works with foreach.

The docs for foreach say:

"Iteration over struct and class objects can be done with ranges. 
For foreach, this means the following properties and methods must 
be defined: .empty ... .front ... .popFront()"

But when I try to access any of those properties or methods for 
stdio.lines, I get compilation errors:

   1 import io = std.stdio;
   2
   3 void main(string[] args) {
   4
   5     auto infile = io.File(args[1], "r");
   6
   7     auto filelines = io.lines(infile);
   8
   9     io.writeln(filelines.front);
  10     io.writeln(filelines.empty);
  11     io.writeln(filelines.popFront());
  12 }

test_filechunking.d(9): Error: no property 'front' for type 
'lines'
test_filechunking.d(10): Error: no property 'empty' for type 
'lines'
test_filechunking.d(11): Error: no property 'popFront' for type 
'lines'

Why is this?

I'm using ldc2 for compilation, FWIW.

Andrew



More information about the Digitalmars-d-learn mailing list