struct Tuple(T...) {
T data;
alias data this;
}
void main() {
Tuple!(uint, float) foo;
foreach(elem; foo) {} // Error: Cannot infer type for elem.
}
The same applies when this is aliased to an array instead of a tuple.
Yep, also fails for arrays.
btw, adding the type to elem yields:
Error: undefined identifier module test.opApply
Error: opApply() function for StructType must return an int
Still fails for arrays.
struct Foo
{
int[] data;
alias data this;
}
void main() {
Foo foo;
foreach(elem; foo) {} // Error: Cannot infer type for elem.
}
Comment #5 by k.hara.pg — 2011-08-23T20:40:14Z
(In reply to comment #4)
> Still fails for arrays.
Which version did you use? Git master (0b47c51f13) can compile it in my environment (Windows 7 64bit).
Comment #6 by hoganmeier — 2011-08-24T04:49:52Z
Sorry something must have gone wrong when I compiled dmd.
It does work with arrays now.