Creating a Sub-view of a non - RA (hasSlicing) range.

monarch_dodra monarch_dodra at gmail.com
Sat Jun 30 05:24:57 PDT 2012


On Saturday, 30 June 2012 at 11:35:07 UTC, Tobias Pankrath wrote:
> std.algorithm.take.
>
> But I would generally avoid SList.

Thanks, but isn't that kind of a crutch solution?

I mean:

1) It creates a new type, so any attempt to use it to modify an 
existing range becomes impossible:
void main()
{
   SList!int slist;
   foreach(i; iota(5,0,-1))
     slist.insertFront(i);

   sr1 = take(sr1, 2); //Nope, not gonna happen
   writeln(sr1);
}

2) The new range is defined as a fixed length from the beginning 
of the range, as opposed to start and finish points. If I were to 
insert new items into my Slist, the new range would just bump the 
top items out of its range.

3) This doesn't work for BidirectionalRanges: The resulting range 
is forward only. For the same reason, it is not possible to have 
a TakeLast for bidirectional ranges.

----
Doesn't D offer any approach to "grow" a range?


More information about the Digitalmars-d mailing list