basics
1 import nxt.dynamic_array : SA = DynamicArray; 2 import std.traits : isIterable; 3 import std.range.primitives : isInputRange; 4 alias C = SA!int; 5 6 auto cs = C([11, 13, 15, 17].s).intoUniqueRange; 7 auto cs2 = cs.dup; 8 9 assert(cs !is cs2); 10 11 assert(cs == cs2); 12 cs2.popFront(); 13 assert(cs2.length == 3); 14 assert(cs != cs2); 15 16 static assert(isInputRange!(typeof(cs))); 17 static assert(isIterable!(typeof(cs))); 18 19 assert(!cs.empty); 20 assert(cs.length == 4); 21 assert(cs.front == 11); 22 assert(cs.back == 17); 23 24 cs.popFront(); 25 assert(cs.length == 3); 26 assert(cs.front == 13); 27 assert(cs.back == 17); 28 29 cs.popBack(); 30 assert(cs.length == 2); 31 assert(cs.front == 13); 32 assert(cs.back == 15); 33 34 assert(cs.frontPop() == 13); 35 assert(cs.length == 1); 36 assert(cs.front == 15); 37 assert(cs.back == 15); 38 39 assert(cs.backPop() == 15); 40 assert(cs.length == 0); 41 assert(cs.empty);
combined with Phobos ranges
import nxt.dynamic_array : SA = DynamicArray; alias C = SA!int; assert(C([11, 13, 15, 17].s) .intoUniqueRange() .filterUnique!(_ => _ != 11) .mapUnique!(_ => 2*_) .equal([2*13, 2*15, 2*17]));
A generator is a range which owns its state (typically a non-reference counted container).