PackedAliasSeq?
Petar
Petar
Sat Feb 24 08:05:49 UTC 2018
On Saturday, 24 February 2018 at 06:14:52 UTC, deadalnix wrote:
> On Thursday, 22 February 2018 at 19:26:54 UTC, Andrei
> Alexandrescu wrote:
>> 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
>
> Isn't a packed AliasSeq just a tuple ?
It is not a tuple (in the `std.typecons.Tuple` sense) if it can
contain values, types and other kinds of symbols. I think a more
appropriate name would be AliasTuple - an AliasSeq that doesn't
auto-expand.
More information about the Digitalmars-d
mailing list