https://issues.dlang.org/show_bug.cgi?id=21891

--- Comment #4 from Andrei Alexandrescu <and...@erdani.com> ---
(In reply to Paul Backus from comment #2)
> (In reply to Andrei Alexandrescu from comment #0)
> > So in fact 1 is bindable to an alias but somehow not in all contexts!
> 
> Specifically: an expression can bind to a template alias parameter, but is
> not allowed on the right-hand side of an alias declaration.
> 
> The reason `alias Y = X;` works but `alias Y = X[0];` doesn't is that `X` by
> itself on the right-hand side is parsed as a symbol, not an expression. The
> variadic parameter is a distraction.

Hm... how does this fit then? Just found it in core.internal.traits:

template maxAlignment(U...)
{
    static if (U.length == 0)
        static assert(0);
    else static if (U.length == 1)
        enum maxAlignment = U[0].alignof;
    else static if (U.length == 2)
        enum maxAlignment = U[0].alignof > U[1].alignof ? U[0].alignof :
U[1].alignof;
    else
    {
        enum a = maxAlignment!(U[0 .. ($+1)/2]);
        enum b = maxAlignment!(U[($+1)/2 .. $]);
        enum maxAlignment = a > b ? a : b;
    }
}

template classInstanceAlignment(T)
if (is(T == class))
{
    alias classInstanceAlignment = maxAlignment!(void*, typeof(T.tupleof));
}


Does that work because there's a template instantiation on the right-hand side?

--

Reply via email to