On Fri, Jun 12, 2009 at 11:00 AM, Jarrett
Billingsley<[email protected]> wrote:
> On Fri, Jun 12, 2009 at 12:10 AM, Ellery
> Newcomer<[email protected]> wrote:
>> what is up with this code?
>>
>> auto t = tuple(1,'a',3.333,false);
>> pragma(msg,typeof(t.tupleof[2 .. $]).stringof);
>>
>> spits out
>>
>> (double, bool, int, char, double, bool)
>>
>
> It has to do with the way Tuple is implemented in std.typecons:
>
>    union
>    {
>        Types field;
>        mixin(tupleFields!(0, T));
>    }
>
> "field" is of type (double, bool, int, char), and the mixin defines
> something like "struct { double _0; bool _1; int _2; char _3; }".
> Since it's a union, the field member overlaps with the anonymous
> struct, just giving you two different ways of accessing the same
> member: t.field[0] or t._0.
>
> When DMD does the tupleof, it puts all the union members in the tuple,
> giving you what looks like a duplicated type list.
>
> You can instead use:
>
>        pragma(msg,typeof(t.field[$ - 2 .. $]).stringof);

Er,

        pragma(msg,typeof(t.field[2 .. $]).stringof);

Reply via email to