Article on Tuples
Don Clugston
dac at nospam.com.au
Thu Nov 16 01:32:30 PST 2006
Walter Bright wrote:
> Don Clugston wrote:
>> Walter Bright wrote:
>>> http://www.digitalmars.com/d/tuple.html
>>
>> "A tuple is a sequence of elements. Those elements can be types,
>> expressions, or aliases."
>>
>> Is this wording correct? How can you make an alias tuple?
>
> Just pass in symbols as template arguments to a U...
Awesome! This is even better than I thought.
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"
}
-------------
Also, is there any way to get .tupleof to return an alias tuple?
For example, you can't write
alias S.tupleof[0] R;
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