dmd.common.bitfields
A library bitfields
utility
License
Source:
common/bitfields
.d
Documentation: https://dlang.org/phobos/dmd_common_bitfields.html
-
Declaration
string
generateBitFields
(S, T)() if (__traits(isUnsigned, T));Generate code for bit fields inside a struct/class body
Parameters
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
Return Value
D code with a bit fields variable and getter / setter functions
Examples
static struct B { bool x; bool y; bool z; } static struct S { mixin(generateBitFields!(B, ubyte)); } 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.z);