digitalmars.D - Type tuple pointers
- Freddy (14/14) May 21 2015 Why don't pointers and .sizeof work with typetuples
- Alex Parrill (5/19) May 21 2015 'Type' tuples are compile-time tuples of types, values, and
- Dicebot (5/7) May 21 2015 Sadly, you are wrong on this one - this is actually a valid
- Alex Parrill (5/12) May 21 2015 So it creates a variable for each type in the tuple, and stores
- Timon Gehr (3/15) May 21 2015 Well, one might somewhat sensibly treat Seq!(char,char)* as
- Timon Gehr (2/19) May 21 2015 Meant to say Seq!(int,char)* -> Seq!(int*,char*).
- Timon Gehr (9/15) May 21 2015 A wacky property of such variable declarations is this one:
- John Colvin (2/21) May 21 2015 Yikes.
- Meta (10/29) May 21 2015 import std.stdio;
- Timon Gehr (15/37) May 21 2015 What happens is that the syntax tree of the initializer is copied.
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
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
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
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: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.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
On 05/21/2015 06:05 PM, Alex Parrill wrote:On Thursday, 21 May 2015 at 15:37:42 UTC, Dicebot wrote:Well, one might somewhat sensibly treat Seq!(char,char)* as Seq!(char*,char*). :o)On Thursday, 21 May 2015 at 15:30:59 UTC, Alex Parrill wrote: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.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
On 05/21/2015 06:14 PM, Timon Gehr wrote:On 05/21/2015 06:05 PM, Alex Parrill wrote:Meant to say Seq!(int,char)* -> Seq!(int*,char*).On Thursday, 21 May 2015 at 15:37:42 UTC, Dicebot wrote:Well, one might somewhat sensibly treat Seq!(char,char)* as Seq!(char*,char*). :o)On Thursday, 21 May 2015 at 15:30:59 UTC, Alex Parrill wrote: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.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
On 05/21/2015 05:37 PM, Dicebot wrote:On Thursday, 21 May 2015 at 15:30:59 UTC, Alex Parrill wrote: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); }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
On Thursday, 21 May 2015 at 16:11:30 UTC, Timon Gehr wrote:On 05/21/2015 05:37 PM, Dicebot wrote:Yikes.On Thursday, 21 May 2015 at 15:30:59 UTC, Alex Parrill wrote: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); }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
On Thursday, 21 May 2015 at 16:11:30 UTC, Timon Gehr wrote:On 05/21/2015 05:37 PM, Dicebot wrote: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.On Thursday, 21 May 2015 at 15:30:59 UTC, Alex Parrill wrote: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); }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
On 05/21/2015 09:36 PM, Meta wrote:On Thursday, 21 May 2015 at 16:11:30 UTC, Timon Gehr wrote: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 }On 05/21/2015 05:37 PM, Dicebot wrote:... Certainly weird and unexpected behaviour.On Thursday, 21 May 2015 at 15:30:59 UTC, Alex Parrill wrote: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); }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