iterating through members of bitfields
Nestor via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Jan 18 04:17:55 PST 2017
On Wednesday, 18 January 2017 at 01:15:05 UTC, Ali Çehreli wrote:
> Not available but it should be possible to parse the produced
> code:
>
> import std.bitmanip;
>
> string makeBitFieldPrinter(string fieldImpl) {
> return q{
> void printBitFields() const {
> import std.stdio: writeln;
> writeln("Please improve this function by parsing
> fieldImpl. :)");
> }
> };
> }
>
> struct S {
> enum myFields = bitfields!(int, "a", 24,
> byte, "b", 8);
>
> pragma(msg, "This is the mixed-in bit field
> code\n---------\n",
> myFields, "\n----------");
>
>
> mixin (myFields);
> mixin (makeBitFieldPrinter(myFields));
> }
>
> void main() {
> const s = S();
> s.printBitFields();
> }
>
> Of course that would depend on the implementation of
> bitfields(), which can change without notice.
>
> Ali
Thanks Ali, I was using bitfields according to documentation, but
now I see that way I can't access the mixin string:
struct S {
mixin(bitfields!(
bool, "f1", 1,
uint, "f2", 4,
uint, "f3", 3)
);
}
More information about the Digitalmars-d-learn
mailing list