How is `auto` and not `alias` appropriate for alias sequences?
Shriramana Sharma via Digitalmars-d
digitalmars-d at puremagic.com
Fri Dec 11 21:52:37 PST 2015
ZombineDev wrote:
>>struct Foo { int val; string name; }
>>Foo foo = {1, "one"};
>>auto t = foo.tupleof;
>>
>> Trying to use `alias` i.o. `auto` above fails.
>>
>> Now IIUC, trying to take the address of t fails, so it's still
>
> auto can refer only to run-time values.
>
> foo is run-time value.
In which case, why should taking its address fail? If I try to do:
auto tp = &t;
I'm getting:
Error: tuple(__t_field_0, __t_field_1) is not an lvalue
What the!? *After* I assign it to a variable, it still says it's not an
lvalue? I mean I understand if I can't take the address of a compiler-
created temporary rvalue, but why can't I take its address even after I
assign it to a newly created variable? Does the variable t have an address
in memory or not?
I understand that:
alias t2 = foo.tupleof;
doesn't work since you cannot give an alias to an rvalue temporary, since t2
would be pointing to nothing after the (immediate) destruction of the
temporary tuple object. But I can still do:
alias t2 = t;
So why can't I do:
auto tp = &t;
???
Note that the following, which should be equivalent, works:
alias FooTuple = Tuple!(int, string);
FooTuple footu = FooTuple(1, "one");
auto ttp = &footu;
--
Shriramana Sharma, Penguin #395953
More information about the Digitalmars-d
mailing list