Consevutive calls to r.front

Dennis Ritchie via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jun 7 17:55:03 PDT 2015


On Monday, 8 June 2015 at 00:42:12 UTC, Mike Parker wrote:
> When implementing a custom range, is it correct to say that 
> consecutive calls to r.front with no intervening calls to 
> popFront should return the same value?

Yes. For examle:

import std.stdio, std.range;

template foo(T) {
     auto foo(R)(R range) {
         while (!range.empty) {
             writeln(range.front);
             // .front --> the first element of the range
             range.popFront;
             // .popFront --> to extract the first element of the 
range
         }
     }
}

void main() {
     foo!(int[])([1, 2, 3]);
}


More information about the Digitalmars-d-learn mailing list