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

Steven Schveighoffer schveiguy at gmail.com
Thu Sep 10 19:47:01 UTC 2020


On 9/10/20 1:05 PM, Meta wrote:

> 
> 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?

Doesn't the compiler have to do this anyway so it can define the memory 
layout? I'm curious what the benefit of doing this in a library would be.

-Steve


More information about the Digitalmars-d mailing list