state of ranges

Jonathan M Davis newsgroup.d at jmdavisprog.com
Wed Dec 13 19:33:02 UTC 2017


On Wednesday, December 13, 2017 11:33:35 Steven Schveighoffer via 
Digitalmars-d wrote:
> I don't think there's a requirement for empty not to do any work, it
> just has to return the same value each time.

IIRC, when this was discussed previously, it was decided that you really
couldn't do work in empty. The problem is that under some circumstances at
least, it's perfectly legitimate to skip calls to empty (e.g. if you already
know that there's plenty of elements left in the range, because you've
called save previously and have iterated through at least that many elements
in another copy of the range or because the range has length). it was
decided that you really couldn't do work in empty. It might be legitimate if
your range was not a forward range, but it would only work under
cirmustances where it would be impossible to know whether there are elements
left in the range or not without calling empty - which is not the case when
dealing with forward ranges.

- Jonathan M Davis



More information about the Digitalmars-d mailing list