www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Type tuple pointers

reply "Freddy" <Hexagonalstar64 gmail.com> writes:
Why don't pointers and .sizeof work with typetuples
----
import std.typetuple;
void main(){
     TypeTuple!(int,char)* test;
     TypeTuple!(long,int).sizeof;
}
----
$ rdmd test
test.d(3): Error: can't have pointer to (int, char)
test.d(4): Error: no property 'sizeof' for tuple '(long, int)'
Failed: ["dmd", "-v", "-o-", "test.d", "-I."]

I know they can be wrapped in structs but shouldn't this work in 
the first place.
May 21 2015
parent reply "Alex Parrill" <initrd.gz gmail.com> writes:
On Thursday, 21 May 2015 at 14:55:21 UTC, Freddy wrote:
 Why don't pointers and .sizeof work with typetuples
 ----
 import std.typetuple;
 void main(){
     TypeTuple!(int,char)* test;
     TypeTuple!(long,int).sizeof;
 }
 ----
 $ rdmd test
 test.d(3): Error: can't have pointer to (int, char)
 test.d(4): Error: no property 'sizeof' for tuple '(long, int)'
 Failed: ["dmd", "-v", "-o-", "test.d", "-I."]

 I know they can be wrapped in structs but shouldn't this work 
 in the first place.
'Type' tuples are compile-time tuples of types, values, and aliases. They aren't types themselves, so `TypeTuple!(int, char) var` doesn't make sense. I think you want regular tuples from std.typecons.
May 21 2015
parent reply "Dicebot" <public dicebot.lv> writes:
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'.
May 21 2015
next sibling parent reply "Alex Parrill" <initrd.gz gmail.com> writes:
On Thursday, 21 May 2015 at 15:37:42 UTC, 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'.
So it creates a variable for each type in the tuple, and stores the aliases in `var`? Huh, didn't know that. But still, `TypeTuple!(int,char)` isn't a real type, so having a pointer to one doesn't make sense.
May 21 2015
parent reply Timon Gehr <timon.gehr gmx.ch> writes:
On 05/21/2015 06:05 PM, Alex Parrill wrote:
 On Thursday, 21 May 2015 at 15:37:42 UTC, 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'.
So it creates a variable for each type in the tuple, and stores the aliases in `var`? Huh, didn't know that. But still, `TypeTuple!(int,char)` isn't a real type, so having a pointer to one doesn't make sense.
Well, one might somewhat sensibly treat Seq!(char,char)* as Seq!(char*,char*). :o)
May 21 2015
parent Timon Gehr <timon.gehr gmx.ch> writes:
On 05/21/2015 06:14 PM, Timon Gehr wrote:
 On 05/21/2015 06:05 PM, Alex Parrill wrote:
 On Thursday, 21 May 2015 at 15:37:42 UTC, 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'.
So it creates a variable for each type in the tuple, and stores the aliases in `var`? Huh, didn't know that. But still, `TypeTuple!(int,char)` isn't a real type, so having a pointer to one doesn't make sense.
Well, one might somewhat sensibly treat Seq!(char,char)* as Seq!(char*,char*). :o)
Meant to say Seq!(int,char)* -> Seq!(int*,char*).
May 21 2015
prev sibling parent reply Timon Gehr <timon.gehr gmx.ch> writes:
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); }
May 21 2015
next sibling parent "John Colvin" <john.loughran.colvin gmail.com> writes:
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); }
Yikes.
May 21 2015
prev sibling parent reply "Meta" <jared771 gmail.com> writes:
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); }
import std.stdio; alias Seq(T...)=T; void main(){ char y='a'; Seq!(char,char) a=y++; //ab Seq!(char,char) b=cast(char)(y+1); //bb Seq!(char,char) b=++y; //bc } Certainly weird and unexpected behaviour.
May 21 2015
parent Timon Gehr <timon.gehr gmx.ch> writes:
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 }
May 21 2015