On 12/11/2015 12:18 PM, Shriramana Sharma wrote:
Hello. I just found that the following code compiles without any problem:
struct Foo { int val; string name; }
Foo foo = {1, "one"};
auto t = foo.tupleof;
Trying to use `alias` i.o. `auto` above fails.
...
The alias should compile. This is a compiler bug.
Workaround:
import std.stdio;
alias Seq(T...)=T;
void main(){
struct Foo{int val;string name;}
Foo foo={1,"one"};
alias t=Seq!(foo.tupleof);
}
However, this still might not do what you want. The above alias is the
same as alias t=Seq!(Foo.tupleof);. This is a general and arbitrary
limitation of alias declarations.
Now IIUC, trying to take the address of t fails, so it's still a compile-
time-only construct without "real" i.e. runtime existence. The tuple is in
fact an AliasSeq, no? In which case, I would have thought that `alias` (for
compile-time symbols) and not `auto` (for runtime variables) would be the
appropriate choice.
Can someone please explain this situation? Thanks.
The line
auto t=foo.tupleof;
declares two variables and aliases them into a Seq of name 't'.
(It is the same as Seq!(int,string) t=foo.tupleof; )
t[0] and t[1] are two distinct variables. This is also why you were not
able take the address of t.