http://d.puremagic.com/issues/show_bug.cgi?id=2448
[email protected] changed: What |Removed |Added ---------------------------------------------------------------------------- Severity|normal |major ------- Comment #1 from [email protected] 2009-01-25 23:32 ------- Adding another example and bumping this to major because it stops std.algorithm development dead in its tracks. template ElementType(R) { alias typeof({ R r; return r[0]; }()) ElementType; } bool empty(T)(in T[] a) { return !a.length; } void next(T)(ref T[] a) { assert(a.length); a = a[1 .. $]; } void retreat(T)(ref T[] a) { assert(a.length); a = a[0 .. $ - 1]; } T head(T)(T[] a) { assert(a.length); return a[0]; } ref T toe(T)(T[] a) { assert(a.length); return a[a.length - 1]; } struct Retro(R) { private: R _input; public: bool empty() { return _input.empty; } void next() { _input.retreat; } ElementType!(R) head() { return _input.toe; } } void main() { void test(int[] input) { foreach (e; Retro!(int[])(input)) { } } test([ 1 ]); } --
