Bug 3377 – [tdpl] static foreach should be implemented

Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Linux
Creation time
2009-10-08T12:12:00Z
Last change time
2015-06-09T05:14:56Z
Assigned to
nobody
Creator
andrei

Comments

Comment #0 by andrei — 2009-10-08T12:12:29Z
This should compile: import std.contracts; double unrolledDotProduct(double[] a, double[] b) { enum branches = 4; enforce(a.length == b.length); double result = 0; auto n = (a.length / branches) * branches; double temp[branches]; for (size_t i = 0; i != n; i += branches) { static foreach (j ; 0 .. branches) { temp[j] = a[i + j] * b[i + j]; } result += inline_sum(temp); } foreach (j; n .. a.length) { result += a[j] * b[j]; } return result; }
Comment #1 by default_357-line — 2009-10-08T12:35:53Z
This does compile (on 1.0): template Repeat(T, int I) { static if (!I) alias Tuple!() Repeat; else alias Tuple!(T, Repeat!(T, I - 1)) Repeat; } double unrolledDotProduct(double[] a, double[] b) { const branches = 4; assert(a.length == b.length); double result = 0; auto n = (a.length / branches) * branches; double temp[branches]; for (size_t i = 0; i != n; i += branches) { foreach (j, BOGUS; Repeat!(void, branches)) { temp[j] = a[i + j] * b[i + j]; } result += inline_sum(temp); } foreach (j; n .. a.length) { result += a[j] * b[j]; } return result; }
Comment #2 by bugzilla — 2009-11-18T13:38:27Z
Many problems have come up with the design of this, so will mark as won't implement until a thorough design is developed.