protocol for using InputRanges

Daniel Murphy yebbliesnospam at gmail.com
Sat Mar 29 19:59:45 PDT 2014


""Luís Marques " wrote in message 
news:exmfmqftpykoaxdgluit at forum.dlang.org...

> - Is it allowed for an InputRange to become empty and then not empty 
> again? For a finite RandomAccessRange to increase in length? E.g.:

Not by itself - if a range's empty has returned true, calling empty 
repeatedly should continue to return true.

If you change it externally (ie not by using the range interface) then it 
can become non-empty.

eg

int[] arr;

assert(arr.empty);
arr ~= 3;
// no longer empty, but we used a method outside the range interface to 
change it.

I don't think a random number generator or some hardware device producing 
more data would be a good reason to change empty - range.empty is not asking 
'is there more data ready', it's asking 'are there items left to iterate 
over'.

> - Is it allowed to not call front? E.g.:

Yes.



More information about the Digitalmars-d mailing list