Type tuple pointers

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Thu May 21 12:54:45 PDT 2015


On 05/21/2015 09:36 PM, Meta wrote:
> On Thursday, 21 May 2015 at 16:11:30 UTC, Timon Gehr wrote:
>> On 05/21/2015 05:37 PM, Dicebot wrote:
>>> On Thursday, 21 May 2015 at 15:30:59 UTC, Alex Parrill wrote:
>>>> They aren't types themselves, so `TypeTuple!(int, char) var` doesn't
>>>> make sense.
>>>
>>> Sadly, you are wrong on this one - this is actually a valid variable
>>> declaration which will create two distinct local variables and uses
>>> their aliases in resulting symbol list named 'var'.
>>
>> A wacky property of such variable declarations is this one:
>>
>> import std.stdio;
>> alias Seq(T...)=T;
>>
>> void main(){
>>     char y='a';
>>     Seq!(char,char) x=y++;
>>     writeln(x);
>> }
>...
>
> Certainly weird and unexpected behaviour.

What happens is that the syntax tree of the initializer is copied.

UDA's also do this:

import std.stdio;
alias I(alias a)=a;
void main(){
     int x;
     @(x++) struct S{};
     __traits(getAttributes,S);
     writeln(x); // 1
     @(__traits(getAttributes,S),__traits(getAttributes,S)) struct T{}
     writeln(x); // 1
     __traits(getAttributes,T);
     writeln(x); // 3
}



More information about the Digitalmars-d mailing list