Create an Algebraic type at compile time and more
uknys
uknysx at pm.me
Fri Jun 15 10:53:35 UTC 2018
On Friday, 15 June 2018 at 07:27:22 UTC, Simen Kjærås wrote:
> On Thursday, 14 June 2018 at 19:15:38 UTC, uknys wrote:
>> [...]
>
> First off - Algebraic doesn't work at compile-time[0]:
>
> // Error: memcpy cannot be interpreted at compile time, because
> it has no available source code
> enum a = Algebraic!(int, string)("Hello!");
>
>
> Now, as for getting the list of types with an X UDA:
>
> import std.traits : getSymbolsByUDA;
> pragma(msg, getSymbolsByUDA!(mixin(__MODULE__), X));
>
> However, as you sort-of point out, there's a problem of
> dependencies - if we assign the result of getSymbolsByUDA to a
> symbol (be that a type or an alias, or part of a type, as in
> Algebraic!(getSymbolsByUDA)), then getSymbolsByUDA will need to
> consider that symbol in its search.
>
> In order to do that, we need to know more about the type.
> Theoretically, the compiler might be able to know which UDAs a
> symbol has without having to figure out all the other details,
> but such is not currently the case.
>
>
> To get around these issues, maybe you could make Hello and Toto
> classes instead of structs?
>
> --
> Simen
>
> [0]: https://issues.dlang.org/show_bug.cgi?id=11864
Yeah I saw that Algebraic doesn't work at compile time, then I
thought of using an Interface with one function (execute()) and
making Hello and Toto as classes implementing even if that's
somewhat slower.
Then I could use pragma(msg, getSymbolsByUDA!(mixin(__MODULE__),
X)); and make an array sorted by opcode of this interface. Am I
right about this ?
More information about the Digitalmars-d-learn
mailing list