I've just fixed UFCS for the experimental type function branch

Meta jared771 at gmail.com
Thu Sep 10 17:05:02 UTC 2020


On Thursday, 10 September 2020 at 09:43:34 UTC, Stefan Koch wrote:
> Hi there,
>
> just a quick update.
> limited UFCS for type functions works again.
> i.e.
>
> this code:
>
> ---
> struct S1 { double[2] x; }
>
> static assert(S1.sizeOf == S1.sizeof);
>
> size_t sizeOf(alias t)
> {
>     return t.sizeof;
> }
> ---
>
> will work.

I'm curious, will this also work?

size_t sizeOf(alias t)
{
     size_t result;
     /* static? */ if (__traits(isScalar))
     {
         static if (is(t == int))
             result += 32;
         else static if (...)
         ...
     }
     else static if (is(t == A[n], A, size_t n))
         result += A.sizeOf * n
     else static if (...)
         ...
     else
         /* static? */ foreach (field; t.tupleof)
             result += field.sizeOf

     return result;
}

Basically, is the implementation at a level where sizeOf can be 
turtles all the way down, with minimal or no reliance on __traits?


More information about the Digitalmars-d mailing list