Proposal for SentinelInputRange

Chris Nicholson-Sauls ibisbasenji at gmail.com
Thu Feb 28 23:02:48 PST 2013


On Friday, 1 March 2013 at 06:33:42 UTC, deadalnix wrote:
>
> struct GenericSentinelRange(R, Sentinel) {
>     R r;
>
>     @property auto front() {
>         return r.front;
>     }
>
>     void popFront() {
>         r.popFront();
>     }
>
>     @property empty() {
>         return r.front == Sentinel;
>     }
> }

That's exactly what I wrote as well, when I played with the idea 
before posting.  Except I just called the sentinel constant S and 
added 'enum sentinel = S;' -- not significant extra work.

> We don't need a new type of range at all. You confuse 
> legitimate uses case for using a sentinel to terminate a range 
> and uses case where an actual sentinel range is needed.

I'm not confused. The use case for a sentinel range /type/ is 
always going to be the same, and singular: automating legitimate 
use cases for sentinels.  So, in effect, an argument for one is 
as good as for the other, when I'm only responding to the calls 
for use case examples. My mistake was in not making it clear that 
I was responding just to those, sorry.

> You can live without, and guess what : if you use LDC (and 
> probably GDC) you'll get the performance boost Walter is 
> talking about.

Which presupposes that I *can* use LDC (or GDC). For many people, 
it may not be an option.  And last time I tried (which has been 
months now, admittedly) I couldn't get LDC to work for me at all, 
which is a shame since I'm actually very much interested in it.  
Either way, reliance on implementation details is not a good 
thing.


More information about the Digitalmars-d mailing list