How is `auto` and not `alias` appropriate for alias sequences?
ZombineDev via Digitalmars-d
digitalmars-d at puremagic.com
Fri Dec 11 07:03:37 PST 2015
On Friday, 11 December 2015 at 14:56:01 UTC, ZombineDev wrote:
> On Friday, 11 December 2015 at 14:25:45 UTC, Timon Gehr wrote:
>> On 12/11/2015 03:12 PM, ZombineDev wrote:
>>>
>>> alias can refer to types, templates, template argument lists
>>> and
>>> compile-time expressions. It can't refer to run-time
>>> variables.
>>
>> Yes it can.
>>
>> void main(){
>> int x=0;
>> alias y=x;
>> y=2;
>> assert(x==2)
>> }
>>
>> It cannot refer to a field or method of a runtime variable
>> though (it still compiles, but the 'this' reference is just
>> thrown away).
>
> Yeah, I forgot to add that it can refer to symbols. Using this
> featue, you can implement a pass by name function (in addition
> to pass by value and pass by reference / address).
To clarify: By using alias you can refer to one symbol through
another name.
So alias can refer to variables, but not to values.
Currently, I think this is restricted to only symbols of run-time
variables in the same scope (same function, same class, etc.) -
only one level of indirection.
More information about the Digitalmars-d
mailing list