The Expressiveness of D

Lutger lutger.blijdestijn at gmail.com
Tue Nov 2 07:24:31 PDT 2010


%u wrote:
...
> 
> template T(A...) { alias A T; }
> 
> void main() {
>   auto a = true ? new B : new C;
> // these don't work - why?
> //  auto b = [new B, new C];
> //  auto c = { return [1: new B,2: new C]; };

I think it should, it works for arithmetic types. See this bug report:

http://d.puremagic.com/issues/show_bug.cgi?id=3543
 
>   T!(int,int) e = (1,2);

I am surprised this works since D doesn't have a tuple literal syntax.

>   e = T!(3,4);
> 
> // ah - so (1,2) syntax on initialization, T!(1,2) when assigning!
>   T!(int,int) d = T!(1,2);
> 
>   e = d;
> 
> // tuples aren't first class, why?
> //  auto f = { return e; };
> }

There has been discussion about this, as mentioned by bearophile. 

In summary, the reason for not having first class tuples is that current 
language constructs provide sufficient means to express tuples as a library 
type, see http://www.digitalmars.com/d/2.0/phobos/std_typecons.html#Tuple.

You can do most - but not all - of what builtin tuples could do with that 
template. 



More information about the Digitalmars-d mailing list