Sourcecommon/bitfields.d
Documentationhttps://dlang.org/phobos/dmd_common_bitfields.html
generateBitFields(S, T, string field = "", int bitOff = 0, int ID = __LINE__)()| S | type of a struct with only boolean fields, which should become bit fields |
| T | type of bit fields variable, must have enough bits to store all booleans |
| field | if provided, assume it is declared and initialized elsewhere |
| bitOff | start using bits at the given offset |
enum E{ a, b, c,}staticstruct B{bool x;bool y; E e = E.c;bool z = 1;privateubyte w = 77;}staticstruct S{mixin(generateBitFields!(B,ushort));}S s;assert(!s.x);s.x =true;assert(s.x);s.x =false;assert(!s.x);s.y =true;assert(s.y);assert(!s.x);assert(s.e == E.c);s.e = E.a;assert(s.e == E.a);assert(s.z);assert(s.w == 77);s.w = 3;assert(s.w == 3);