Article on Tuples

Walter Bright newshound at digitalmars.com
Thu Nov 16 02:19:32 PST 2006


Don Clugston wrote:
> One problem -- it seems that if the tuple has a mix of types and 
> instances, you can't index it.
> -------------
> struct S { int x; long y; }
> 
> template Tuple(E...)
> {
>     alias E Tuple;
> }
> 
> void main()
> {
>     int q;
> 
>     alias Tuple!(S, q) Z;
>     alias Z[0] R; // fails -- "tuple E is used as a type"
> }
> -------------

About the only thing you can do with mixed tuples is pass them as 
arguments to another template.

> Also, is there any way to get .tupleof to return an alias tuple?
> For example, you can't write
> alias S.tupleof[0] R;

That's because you can't have an alias to an expression. You can have a 
pointer to an expression, though:

	auto R = &S.tupleof[0];

> Nor (more importantly) can you pass it as an template alias parameter:
> 
> template Z(alias W) {
>     const int Z = 2;
> }
> 
> const int x = Z!((S.tupleof[0]));
> 
> (If it worked, I could write a dump!(X) which would display all the 
> names of the members of X, with their values...).



More information about the Digitalmars-d-announce mailing list