Lars T. Kyllingstad Wrote: > To avoid the boilerplate, you could write a mixin that defines the > iteration primitives for you. > > mixin template IterationFuncs() > { > int index; > bool empty() { return index == length; } > auto front() { return opIndex(index); } > void popFront() { ++index; } > // ... etc. > } > > Then you'd just have to define opIndex() and length(), and the mixin does > the rest for you. > > struct MyRange(T) > { > T opIndex(int i) { ... } > @property int length() { ... } > mixin IterationFuncs!(); > } > > (I haven't tested the code above, so it probably has bugs, but you get > the point.) > > -Lars
Maybe this should be added to std.range? http://d.puremagic.com/issues/show_bug.cgi?id=5351