state of ranges

Dukc ajieskola at gmail.com
Wed Dec 13 20:40:46 UTC 2017


On Wednesday, 13 December 2017 at 10:15:10 UTC, ag0aep6g wrote:
>
> `front` can't assume that `empty` has been called before. For a 
> well-behaved range, `front` must work the same whether you've 
> called `empty` or not (given that the range isn't actually 
> empty).

That last point is what I meant: it cannot assume empty() being 
called BUT it can assume that it WOULD have returned false it it 
were. So there is no problem with the program crashing when 
calling front() of an empty range. Therefore, there is no need to 
manually do stuff like if(inited) because if the elements are not 
initialized, the range would obviously be empty. Assuming I 
understood the intention of that code correctly.


More information about the Digitalmars-d mailing list