PackedAliasSeq?
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Thu Feb 22 19:26:54 UTC 2018
After coding https://github.com/dlang/phobos/pull/6192 with AliasSeq,
the experience has been quite pleasurable. However, in places the
AliasSeq tends to expand too eagerly, leading to a need to "keep it
together" e.g. when you need to pass two of those to a template.
I worked around the issue by nesting templates like this:
template Merge(T...)
{
template With(U...)
{
static if (T.length == 0)
alias With = U;
else static if (U.length == 0)
alias With = T;
else static if (T[0] < U[0]
|| T[0] == U[0] && T[1].stringof <= U[1].stringof)
alias With =
AliasSeq!(T[0], T[1], Merge!(T[2 .. $]).With!U);
else
alias With =
AliasSeq!(U[0], U[1], Merge!T.With!(U[2 .. $]));
}
}
So instead of the unworkable Merge!(AliasSeq!(...), AliasSeq!(...)), one
would write Merge!(AliasSeq!(...)).With!(AliasSeq!(...)).
The problem remains for other use cases, so I was thinking of adding to
std.meta this simple artifact:
template PackedAliasSeq!(T...)
{
alias expand = AliasSeq!T;
}
That way, everything stays together and can be expanded on demand.
Andrei
More information about the Digitalmars-d
mailing list