www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Should Tuple!( T, "name" ) be implicitly castable to Tuple!T?

I've noticed that (std.typecons') tuples now are assignable to
structurally equal tuples. I'm not sure I agree fully on the choices
made, and figured a discussion might be in order.

Tuple!(int, "a") a;
Tuple!int b;
b = a;

IMO, this is good and correct. A tuple without field names is to me a
mere black box with data inside, and throwing some other data in there
is ok.

Tuple!( int, "a" ) a;
Tuple!int b;
a = b;

This, I am not so sure about. A black box is turned into structured
data. I guess it's ok.

Tuple!( int, "a" ) a;
Tuple!( int, "b" ) b;
a = b;

This I feel, is wrong. a is of a different type from b.

void foo( Tuple!int );
Tuple!(int, "a") a;
foo( a );

This should work. It may be that alias this is not yet good enough to
make this work, but I believe it should be doable by having tuples with
named fields use alias this to turn into tuples without named fields,
and tuples without named fields taking care of []-lookup.

struct Tuple(T...) if(containsStrings!T) {
     Tuple!(noStrings!T) get() {...}
     alias get this;

struct Tuple(T...) if(!containsStrings!T) {
     T field;
     alias field this;

Dec 21 2010