On 2/9/13 3:49 PM, Walter Bright wrote:
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.
Yah, that all would fit C-style strings and singly-linked lists like a glove. I've been long hoping the opportunity to define such a range would present itself :o).
Andrei
