What are tuples exactly? (D's tuples considered harmful)

Morlan home at valentimex.com
Fri Feb 25 03:39:31 PST 2011


While trying to understand the expand mechanism presented in the TDPL book I
tried to read std.typetuple and std.typecons files. I found a true nightmare
in those files in the form of an almost infinite chain of aliases and macro
processing. How can one understand a written text if the words are redifined
in every other line? And people say that goto instruction is bad? Please give
me a break.

Anyway, at some point I realized that I cannot understand what is going on
because there is some language mechanism in action which I do not know. I
wrote a small program to confirm this. Here it is:

struct S { TypeTuple!(int, double) field; }
void main(){
	S mys;
	mys.field[0] = 4;
	mys.field[1] = 4.4;
}

It compiles all right. But if you replace the S's definition with {int, double
field;}
it does not compile. So tuples are clearly much more than a sequence of types
and they trigger a completely different semantic action than a plain sequence
of types. Is there a precise definition of tuples somewhere?




More information about the Digitalmars-d mailing list