struct B { float i; double j; int k; void test() { foreach (m; this.tupleof) { writefln(typeof(m).stringof); } } } void main() { B b; b.test(); }
If a struct has a member that is a struct, I would expect that this would work. As for non struct members, the logical thing to do would be to make that work anyway to avoid corner cases. Or are you saying the result of the tupleof is not what it should be?
My bad, I forgot attaching the expected and actual result. Here they are: Expected output: float double int Actual output: float float float The tuple is ok, but foreach body "instantiated" incorrectly.
I believe this is relevant: import std.stdio; void foo(T)(T t) { assert(is(typeof(t) == T)); writeln(T.stringof); writefln(typeof(t).stringof); } struct A { int i; void test() { foreach (m; this.tupleof) { foo(m); // line 17 } } } void main() { foo(new A()); } Expected output: A* A* Actual output: A* int Looks like result of typeof(t) is evaluated just once at compile time and then reused at every template instantiation. Commenting line 17 hides the issue.
What version? version: 1026 // what codepad.org uses float double int
> Version: 2.020
Fixed DMD2.023 (failed in 2.022).