Extending bitfields to enumerations of any enumerator type

monkyyy crazymonkyyy at gmail.com
Wed Oct 8 22:42:01 UTC 2025


On Wednesday, 8 October 2025 at 20:37:02 UTC, Per Nordlöw wrote:
> Given
>
> ```d
> struct S {
> 	Field field:1;
> }
> ```
>
>
> , is there a reason why
>
> ```d
> enum Field : string { none = [], dot = "." }
> ```
>
> isn't allowed and errors as
>
> ```
> (1,34): Error: bitfield type `FieldNamePrefix` is not an 
> integer type
> ```
>
> ?
>
> Instead I currently have to encode this as
>
> ```d
> enum Field : ubyte { none, dot }
>
> string toString(in Field arg) pure nothrow @nogc {
> 	final switch (arg) with (arg) {
> 	case none: return [];
> 	case dot: return ".";
> 	}
> }
> ```
>
> .

string is a very bad example, it be 128 bits
char could be more reasonable, but are you defining a 5 bit lower 
case format?
unions already exist and bitshifts to compress rapidly stop 
making sense for things that airnt bools


More information about the Digitalmars-d mailing list