[hackathon] An article about metaprogramming
Mafi via Digitalmars-d
digitalmars-d at puremagic.com
Wed Apr 29 11:13:09 PDT 2015
On Wednesday, 29 April 2015 at 16:55:58 UTC, bearophile wrote:
> Mafi:
>
>> https://marfisc.wordpress.com/2015/04/29/using-d-templates-for-gamedev/
>>
>> What do you think? Any remarks?
>
>>The SDL_Event is a union. Accessing it is inherently unsafe for
>>type consistency and memory safety. The SDL library mitigates
>>this problem by adding a tag (the member type) which encodes
>>which union-member is to be used.<
>
> In Rust you use the built-in tagged unions and call it a day...
Well, it is an already existing C library I am only adapting. And
additionally the shonwn template encapsulates the whole outer
loop as well.
>
>[...]
>
> The default should be aligned just like the other cases. Often
> is a good idea to use "final switch" with enumerations.
> Probably there are ways to make that code more dry, using a
> TypeTuple of pairs like ("SDL_QUIT", "quit").
>
> Bye,
> bearophile
I cannot use a final switch there because it is not enumerated
type. The values are just constants. Moreover I want to skip
unneeded labels and instead unify them into the default branch.
This is impossible with a final switch.
More information about the Digitalmars-d
mailing list