August 16, 2013 Re: Places a TypeTuple can be used | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | On Friday, 16 August 2013 at 15:40:35 UTC, Ali Çehreli wrote:
> Exactly. Only then this concept would be easy to understand and explain. It would make "a comma-separated list of expressions/types" a language construct. Done.
It does complicate things that sometimes TypeTuple is accepted in cases where comma-separated list does not:
import std.typetuple;
void main()
{
//alias TT = TypeTuple!(int, string);
//TT twoVars;
(int, string) twoVars; // do you expect this to work?
static assert(is(typeof(twoVars[0]) == int));
static assert(is(typeof(twoVars[1]) == string));
}
The fact that built-in concept of tuple can't be expressed with built-in syntax creates lot of learning issues. In that regard, defining "list of expressions/types" as language construct goes as a solution both ways.
I honestly think it is one of the cases where idea "wow, we can have library support for type tuples instead of language support!" has failed with an enormous technical debt.
|
August 16, 2013 Re: Places a TypeTuple can be used | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dicebot | On 08/16/2013 09:02 AM, Dicebot wrote: > It does complicate things that sometimes TypeTuple is accepted in cases > where comma-separated list does not: > > import std.typetuple; > > void main() > { > //alias TT = TypeTuple!(int, string); > //TT twoVars; > (int, string) twoVars; // do you expect this to work? > static assert(is(typeof(twoVars[0]) == int)); > static assert(is(typeof(twoVars[1]) == string)); > } No, I would not expect that line to work. However, I am totally amazed that your commented-out code works! Wow! :) import std.typetuple; void main() { alias TT = TypeTuple!(int, string); TT twoVars; static assert(is(typeof(twoVars[0]) == int)); static assert(is(typeof(twoVars[1]) == string)); } I am speechless. :) Ali |
August 16, 2013 Re: Places a TypeTuple can be used | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | On Friday, 16 August 2013 at 21:41:10 UTC, Ali Çehreli wrote:
> import std.typetuple;
>
> void main()
> {
> alias TT = TypeTuple!(int, string);
> TT twoVars;
> static assert(is(typeof(twoVars[0]) == int));
> static assert(is(typeof(twoVars[1]) == string));
> }
>
> I am speechless. :)
>
> Ali
Seeing as TypeTuple aliases itself away on instantiation (There is no such thing as a TypeTuple, only a builtin tuple created with TypeTuple), this is the same principle as
void foo(T ...)()
{
T t = T.init;
foreach(el; t)
write(el,",");
}
foo!(int, double)(); //prints: "0,nan"
|
Copyright © 1999-2021 by the D Language Foundation