Compile-Time Size Checking of Enum Members of std.bitmanip.bitfields

via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jan 19 03:40:06 PST 2015


On Monday, 19 January 2015 at 11:23:11 UTC, bearophile wrote:
> File an enhancement and/or submit a Phobos patch.

Ok, great. I'll try fixing this in a PR.

Further...I propose to enhance `bitfields` to automatically
deduce bitfield lengths in the following way.

      autoBitfields!(ubyte, "x", 3, // explicit length
                     E, "e", -1, // field length is deduced
                     ubyte, "y", 3
                     // padding to whole bytes is deduced
                     )

Typical deductions are
- enums: E.max - E.min + 1 (this requires offsetting logic in
packing)
- bool: 1

Alternatively I guess we could use a specific enum type to
indicate that the field length should be deduced to minimum
required length.

I guess we could add a template overload to bitfields with a
specific first  enum parameter that triggers size deduction,
instead of autoBitfields aswell.

What do you think?


More information about the Digitalmars-d-learn mailing list