alias tuples?

Janice Caron caron800 at googlemail.com
Sat Oct 13 23:01:47 PDT 2007


We've got value tuples, and we've got type tuples. Could we also have
alias tuples?

Here's what I mean. Right now I can do:

struct A
{
    X x;
    Y y;
    Z z;

    mixin Serialize!(x,y,z);
}
A a;

template Serialize(alias x,alias y,alias z)
{
    void serialize()
    {
        x.serialize();
        y.serialize();
        z.serialize();
    }
}

where the types X, Y and Z all have a serialize() function (and so on
recursively for every object in need of serialization). Now it seems
to me, if I wanted to make Serialize!() variadic, I'd need not a value
tuple, nor a type tuple, but an "alias tuple". I'd want to be able to
write something like:

struct A
{
    X x;
    Y y;
    Z z;

    mixin Serialize!(this.aliastupleof); /* expands to (x,y,z) */
}
A a;

template Serialize(alias T...)
{
    void serialize()
    {
        foreach(a;T)
            a.serialize();
    }
}

Of course this won't work right now. The template won't compile
because (alias T...) has no meaning, and even if it did, structs don't
have an aliastupleof property.

Thoughts?



More information about the Digitalmars-d mailing list