I've just fixed UFCS for the experimental type function branch
Paul Backus
snarwin at gmail.com
Thu Sep 10 18:05:23 UTC 2020
On Thursday, 10 September 2020 at 17:05:02 UTC, 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?
One thing built-in .sizeof does that no user-code version can do
is "freeze" the size of a type to prevent additional members from
being added. For example, if you try to compile this code:
struct S
{
int a;
enum size = S.sizeof;
mixin("int b;");
}
...you'll get an error:
onlineapp.d-mixin-5(5): Error: variable onlineapp.S.b cannot be
further field because it will change the determined S size
More information about the Digitalmars-d
mailing list