How to strip struct/class invariants?

Artem Tarasov via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jul 5 08:39:47 PDT 2015


On Sunday, 5 July 2015 at 14:44:30 UTC, John Colvin wrote:
>
> struct A
> {
>     ubyte[B.sizeof] mem;
>     @property ref B b()
>     {
>         return *cast(B*)(mem.ptr);
>     }
>     mixin std.typecons.Proxy!b;
> }
>

Thanks, I followed your suggestion and effectively rolled out my 
own union implementation. Ugly but it works.

struct A
{
     ubyte[maxSizeof] _data;
     @property ref T _as(T)() inout { return *cast(T*)(_data.ptr); 
}
     alias b = _as!uint;
     alias c = _as!size_t;
     alias d = _as!double;
}



More information about the Digitalmars-d-learn mailing list