protocol for using InputRanges

Walter Bright newshound2 at digitalmars.com
Sat Mar 22 17:50:34 PDT 2014


It's become clear to me that we've underspecified what an InputRange is. The 
normal way to use it is:

     while (!r.empty) {
         auto e = r.front;
         ... do something with e ...
         r.popFront();
     }

no argument there. But there are two issues:

1. If you know the range is not empty, is it allowed to call r.front without 
calling r.empty first?

If this is true, extra logic will need to be added to r.front in many cases.

2. Can r.front be called n times in a row? I.e. is calling front() destructive?

If true, this means that r.front will have to cache a copy in many cases.


More information about the Digitalmars-d mailing list