Operation on Inter-Tuple types

monarch_dodra monarchdodra at gmail.com
Tue Feb 12 06:03:37 PST 2013


This question came up in the pulls.

Given two different Tuple types, it is possible to run an 
operator on said tuples, if the operator is legal for each 
individual field in the tuple. For example.

//----
import std.typecons;

void main()
{
     auto a = Tuple!(  int,     const(char)[])(           2, 
"what".dup);
     auto b = Tuple!(short, immutable(char)[])(cast(short)1, 
"hello");
     a = b;
     assert(a == b);
     assert(!(a < b));
     assert(!(a < b));
     assert(!(a > b));
}
//----

I'm not really sure if this was really ever meant to work this 
way, or if the implementation got luck and allowed it. The 
documentation isn't really very clear about it.

In any case, it begs the question: *Should* Tuples be allowed to 
do this?

The rationale for them *not* being allowed is that the Types are 
different, and for standard aggregate structs, this would not be 
legal, *even if* each field can be cast from one to the other. 
Why should Tuple allow it?

Stances on the matter?


More information about the Digitalmars-d mailing list