How to remove element from an SList?
bearophile
bearophileHUGS at lycos.com
Tue Mar 27 18:46:50 PDT 2012
Ali Çehreli:
> The following worked for me. Note treating the SList as a range
> by []:
>
> import std.container;
> import std.stdio;
> import std.algorithm;
> import std.range;
>
> void main()
> {
> auto l = SList!int(1, 2, 3, 4, 5, 6, 7);
>
> auto a = find(l[], 2); // Search for 2 ...
> l.linearRemove(take(a, 1)); // ... and remove just 2
>
> auto b = find(l[], 6); // Search for 6 ...
> l.linearRemove(b); // ... and remove from there
>
> assert(l == SList!int(1, 3, 4, 5));
> }
That seems an example for the dlang site docs :-)
(It just needs to show the usage of "cursors" to on the list?)
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list