Inserting and removing elements from a sorted container

Dirk dirk at email.address
Sun Nov 19 16:48:00 UTC 2017


On Sunday, 19 November 2017 at 16:05:53 UTC, Jonathan M Davis 
wrote:
>
> I'd suggest that you use std.container.rbtree..RedBlackTree. A 
> red-black tree exactly the sort of data structure that is 
> typically used in a sorted set.
>
> - Jonathan M Davis

Thank you, i will look into it.


I have a question related to ranges:

An input range has an interface like this:

struct inputRange
{
     void popFront();
     @property bool empty();
     @property int front();
}


So if i use a foreach loop to iterate over all elements of a 
range, i would expect the range to shrink for every iteration:

auto list = SList!uint(1,2,3);
auto range = list[].save();
foreach( i; range ) {
   writeln(range);
}

Expected output:
[1,2,3]
[2,3]
[3]

But i get:
[1,2,3]
[1,2,3]
[1,2,3]

Why don't i see the expected output?

Thank you,
Dirk


More information about the Digitalmars-d-learn mailing list