May 08, 2008 Two unrelated | ||||
---|---|---|---|---|
| ||||
The first one is a little program that if correct shows that phobos dyna array reverse may enjoy a specialization for performance purposes: import std.stdio: writefln; import std.c.time; double myclock() { return clock()/cast(double)CLOCKS_PER_SEC; } void main() { alias int Ty; auto a = new Ty[10000]; const uint NLOOP = 1000; auto t = myclock(); for (uint i; i < NLOOP; ++i) a.reverse; writefln("reverse method: ", myclock() - t, " s"); t = myclock(); for (uint i; i < NLOOP; ++i) { if (a.length > 1) { Ty tmp; size_t lo = 0; size_t hi = a.length - 1; for (; lo < hi; lo++, hi--) { tmp = a[lo]; a[lo] = a[hi]; a[hi] = tmp; } } } writefln("reverse: ", myclock() - t, " s"); } ------------------------------------------------------------------ This other little program crashes at the line I have marked with: Internal error: ..\ztc\blockopt.c 609 template Tuple(T...) { alias T Tuple; } template Interval(int n) { static if (n < 1) alias Tuple!() Interval; else alias Tuple!(Interval!(n-1), n) Interval; } int[] foo(int N)() { int[N] a; return a.dup; } void main() { foreach(n; Interval!(198)) // error here auto a = foo!(n); } Bye, bearophile |
Copyright © 1999-2021 by the D Language Foundation