switch to member

Ignacious via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jan 14 08:05:33 PST 2017


On Saturday, 14 January 2017 at 08:30:04 UTC, Meta wrote:
> 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.

Go join the Nazi Youth group, you OSS Sympathizer!


More information about the Digitalmars-d-learn mailing list