Random-access range
1 import std.algorithm : equal; 2 import std.range.primitives : isRandomAccessRange; 3 import std.container.util : make; 4 auto q = Stack!int(); 5 6 assert(equal(q[], new int[0])); 7 q.insertBack(1); 8 assert(equal(q[], [1])); 9 q.insertBack(2); 10 assert(equal(q[], [1, 2])); 11 q.insertBack(3); 12 assert(equal(q[], [1, 2, 3])); 13 q.removeBack(); 14 assert(equal(q[], [1, 2])); 15 q.insertBack(4); 16 assert(equal(q[], [1, 2, 4])); 17 q.removeBack(); 18 assert(equal(q[], [1, 2]));
Stack