switch to member

Meta via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jan 14 00:30:04 PST 2017


On Saturday, 14 January 2017 at 05:29:49 UTC, Nicholas Wilson 
wrote:
> enum XX
> {
>     X = Q.X.offsetof,
>     Y = Q.Y.offsetof
>     //ect.
> }
>
> and then
>
> *(cast(void*)(this) + x) = e; //if inside struct/class
>
> or
> *(cast(void*)(q) + x) = e; // if outside
>
> Unfortunately this loses you `@safe`ty, but as long as you trust
> the value of x then it should be safe to `@trusted` that code.
>
> If you are trying to avoid code duplication the enum 
> declaration of X
> could also be done with a string mixin.

IMO this is massive overkill to save some typing. To the OP, it's 
not really worth it to go to so much trouble. Just write some 
slightly duplicated code and move on.


More information about the Digitalmars-d-learn mailing list