Making sense of ranges

Steven Schveighoffer schveiguy at yahoo.com
Mon Mar 26 12:54:58 PDT 2012


On Sat, 24 Mar 2012 19:07:01 -0400, Stewart Gordon <smjg_1998 at yahoo.com>  
wrote:

> On 24/03/2012 18:57, Ali Çehreli wrote:
> <snip>
>> Iterating an output range is also by popFront(). So what it says is,  
>> put this element to
>> the output range and advance the range. There is a gotcha about this  
>> when the output range
>> is a slice: Whatever is just put into the range is popped right away!  
>> :) [2]
>
> I'm beginning to get it now: the purpose of an output range is to put  
> new data into the underlying container.  So once you've put something  
> in, the remaining range is what's left to be populated.  I had been  
> thinking of outputting in terms of appending to the range, hence the  
> confusion.

The output range is almost an entirely orthogonal concept to an input  
range.  It basically defines a way to output elements.

How an output range directs its elements is up to the output range.  It  
may append, it may overwrite, it may prepend, it can do anything it wants.

The only commonality is that a *writable* input range can also be an  
output range (writable meaning r.front = x works).

-Steve


More information about the Digitalmars-d-learn mailing list