Should Tuple!( T, "name" ) be implicitly castable to Tuple!T?
Simen kjaeraas
simen.kjaras at gmail.com
Tue Dec 21 07:29:23 PST 2010
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.
1:
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.
2:
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.
3:
Tuple!( int, "a" ) a;
Tuple!( int, "b" ) b;
a = b;
This I feel, is wrong. a is of a different type from b.
4:
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.
Basically:
struct Tuple(T...) if(containsStrings!T) {
Tuple!(noStrings!T) get() {...}
alias get this;
}
struct Tuple(T...) if(!containsStrings!T) {
T field;
alias field this;
}
--
Simen
More information about the Digitalmars-d
mailing list