Implements a simple and fast singly-linked list. It can be used as a stack.
1 import std.algorithm.comparison : equal; 2 import std.container : SList; 3 4 auto s = SList!int(1, 2, 3); 5 assert(equal(s[], [1, 2, 3])); 6 7 s.removeFront(); 8 assert(equal(s[], [2, 3])); 9 10 s.insertFront([5, 6]); 11 assert(equal(s[], [5, 6, 2, 3])); 12 13 // If you want to apply range operations, simply slice it. 14 import std.algorithm.searching : countUntil; 15 import std.range : popFrontN, walkLength; 16 17 auto sl = SList!int(1, 2, 3, 4, 5); 18 assert(countUntil(sl[], 2) == 1); 19 20 auto r = sl[]; 21 popFrontN(r, 2); 22 assert(walkLength(r) == 3);
2010- Andrei Alexandrescu. All rights reserved by the respective holders.
This module implements a singly-linked list container. It can be used as a stack.
This module is a submodule of std.container.