Bug 7738 – Can't iterate a std.typecons.Typedef!(int[]) with foreach
Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-03-19T17:33:00Z
Last change time
2013-01-20T15:12:14Z
Keywords
rejects-valid
Assigned to
nobody
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2012-03-19T17:33:07Z
This compiles in DMD 2.059head:
alias int[] MyArray;
void main() {
MyArray arr;
foreach (i, item; arr) {}
}
This doesn't compile:
import std.typecons: Typedef;
alias Typedef!(int[]) MyArray;
void main() {
MyArray arr;
foreach (i, item; arr) {}
}
DMD 2.059head gives the error:
test.d(5): Error: invalid foreach aggregate arr
This simpler code gives the same error:
import std.typecons: Typedef;
alias Typedef!(int[]) MyArray;
void main() {
MyArray arr;
foreach (item; arr) {}
}
My main use cases for typedef are with arrays. So this problem makes std.typecons.Typedef not much useful.
Comment #1 by andrej.mitrovich — 2013-01-20T14:08:09Z
Works in 2.061
Comment #2 by bearophile_hugs — 2013-01-20T15:12:14Z
(In reply to comment #1)
> Works in 2.061
A step forward for D language.