Sentinel InputRange ?

Walter Bright newshound2 at digitalmars.com
Sat Feb 9 12:49:50 PST 2013


On 2/9/2013 12:43 PM, Walter Bright wrote:> Perhaps we can formalize this a bit. 
Define a SentinelInputRange, which has an
 > additional manifest constant with the name 'sentinel'. empty becomes defined as:
 >
 >      empty = front == sentinel;
 >
 > popFront() does not advance if empty. Advancing over a SentinelInputRange can be
 > done the usual:
 >
 >      for (r = range; !r.empty; r.popFront()) { auto e = r.front; }
 >
 > or can be done as:
 >
 >      for (r = range; r.front != sentinel; r.popFront()) { auto e = r.front; }

If it's not clear, SentinelInputRange.front can be called *before* checking 
empty. If it is empty, then the sentinel is returned.



More information about the Digitalmars-d mailing list