Article on Tuples
Bruno Medeiros
brunodomedeiros+spam at com.gmail
Sat Nov 18 09:47:21 PST 2006
Walter Bright wrote:
> 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];
>
Indexed Tuples are only expressions in syntax, not such much
conceptually. What if we could also index tuple elements using template
instantiation:
alias S.tupleof!(0) R;
Then perhaps the aliasing would work with the current compiler/language
rules.
--
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
More information about the Digitalmars-d-announce
mailing list