Interesting work on packing tuple layout

Max Samukha maxsamukha at gmail.com
Mon Jun 15 13:34:18 UTC 2020


On Sunday, 14 June 2020 at 23:30:03 UTC, Andrei Alexandrescu 
wrote:
> It's really easy if members in the layout are given internal 
> names that include information about the original index.

You can construct a list of member aliases in the original order 
and then 'alias this' that:

import std.meta;

struct Tuple(A...) {
     alias Reordered = AliasSeq!(A[1], A[2], A[0]);
     Reordered value;

     alias reordered = AliasSeq!(typeof(this).tupleof);
     alias original = AliasSeq!(reordered[2], reordered[0], 
reordered[1]);
     alias original this;
}

void main() {
     Tuple!(byte, int, short) t;

     static assert(is(typeof(t.tupleof) == AliasSeq!(int, short, 
byte)));

     static assert(is(typeof(t[0]) == byte));
     static assert(is(typeof(t[1]) == int));
     static assert(is(typeof(t[2]) == short));
}


More information about the Digitalmars-d-announce mailing list