View source code
Display the source code in dmd/common/bitfields.d from which thispage was generated on github.
Report a bug
If you spot a problem with this page, click here to create aBugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.Requires a signed-in GitHub account. This works well for small changes.If you'd like to make larger changes you may want to consider usinglocal clone.
Function dmd.common.bitfields.generateBitFields
Generate code for bit fields inside a struct/class body
string generateBitFields(S, T)()
if (__traits(isUnsigned, T));
Parameters
Name | Description |
---|---|
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 |
Returns
D code with a bit fields variable and getter / setter functions
Example
enum E
{
a, b, c,
}
static struct B
{
bool x;
bool y;
E e = E .c;
bool z = 1;
private ubyte w = 77;
}
static struct 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);
writeln(s .e); // E.c
s .e = E .a;
writeln(s .e); // E.a
assert(s .z);
writeln(s .w); // 77
s .w = 3;
writeln(s .w); // 3
Authors
Dennis Korpel
License
Copyright © 1999-2025 by the D Language Foundation | Page generated by ddox.