Places a TypeTuple can be used

Timon Gehr timon.gehr at gmx.ch
Fri Aug 16 04:09:36 PDT 2013


On 08/16/2013 06:14 AM, Ali Çehreli wrote:
> I know of three places a TypeTuple can be used at:
>
> 1) Function parameter list
>
> 2) Template parameter list
>

In fact, no.

template A(Seq!(int,int) a){ enum A=a[0]; } // error

> 3) Array literal element list
>
> Are there more?
>...

I assume you mean just the contexts where it auto-expands in some way?


- Declared type of a tuple of variables (or function parameters):

Seq!(int,int) x;
assert(is(typeof(x[0])==int)&&is(typeof(x[1])==int));


void foo(Seq!(int,int) x);


- Function argument list (including struct constructor calls, excluding 
arguments to overloaded operators):

foo(Seq!(1,2));


- Index argument list:

a[Seq!(1)]


- new argument list(s):

new A(Seq!(1,2));

// new!(Seq!(1,2)) A(Seq!(1,2)); // to be deprecated


- Parent list:

class A: Seq!(B,C){ }


- Array literal element list (for completeness of this list):

[Seq!(1,2)]


I think those might be all usages accepted by DMD.

IMO it should work everywhere a comma-separated list of 
expressions/types is expected.
Some arbitrary limitations implemented by DMD:

- Arguments to (static) assert statement:

assert(Seq!(false, "boom!")); // error

- Arguments to mixin statements:

mixin(Seq!"int x=2;"); // error

- Arguments to overloaded operators:

s.opBinary!"+"(Seq!(s,s)); // ok
s+Seq!(s,s); // error

- Case lists:

switch(1){
     case Seq!(1,2): break; // error
     default: break;
}

- template parameter lists

template A(Seq!(int,int) a){ enum A=a[0]; } // error

- Second argument to comma expression in valid context:

foo((x++,Seq!(1,2))); // error



More information about the Digitalmars-d-learn mailing list