[Issue 1642] New: static foreach support for arrays
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Nov 6 04:53:19 PST 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1642
Summary: static foreach support for arrays
Product: D
Version: 2.007
Platform: PC
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P3
Component: DMD
AssignedTo: bugzilla at digitalmars.com
ReportedBy: dhasenan at gmail.com
The following is required to be executed at compile time, and all data is
available at compile time:
int foo () {
foreach (string letter; ["a", "b", "c"])
pragma (msg, letter);
return 0;
}
static const int i = foo();
The expected output when compiling is:
a
b
c
The actual result when compiling is:
foreach_array.d(5): Error: string expected for message, not 'letter'
The issue: static foreach only works for tuples, and I want to use it on an
array.
This is inconsistent with __traits: the allMembers trait returns an array. If
it returned a more obtuse structure, a tuple, then I wouldn't need to use
recursion with it; and if static foreach supported arrays, that would make even
more code more readable.
--
More information about the Digitalmars-d-bugs
mailing list