digitalmars.dip.ideas - do something with bitfields and switch statements
- monkyyy (21/21) Aug 06 https://forum.dlang.org/thread/fsjfcairmfcdwraxabdk@forum.dlang.org
- Nick Treleaven (4/25) Aug 07 That doesn't seem to fit as part of the remit of `switch`, what
- monkyyy (4/10) Aug 07 its `(bar.a<<2 | bar.b<<1 |bar.c)` in a single op that uses no
https://forum.dlang.org/thread/fsjfcairmfcdwraxabdk forum.dlang.org if bitfields are leaving preview and currently doing nothing special with switch ```d struct foo{ bool a:1; bool b:1; bool c:1; uint i:29; } unittest{ foo bar=foo(false,false,false,1337); switch(bar,3){ case 0: bar.i.writeln; break; default:"bye".writeln; break; } } ``` maybe allow switch to take 2 parameters, if the first is a struct with bit fields, the 2nd is the number of bits it bitshifts off the top
Aug 06
On Wednesday, 6 August 2025 at 19:00:09 UTC, monkyyy wrote:https://forum.dlang.org/thread/fsjfcairmfcdwraxabdk forum.dlang.org if bitfields are leaving preview and currently doing nothing special with switch ```d struct foo{ bool a:1; bool b:1; bool c:1; uint i:29; } unittest{ foo bar=foo(false,false,false,1337); switch(bar,3){ case 0: bar.i.writeln; break; default:"bye".writeln; break; } } ``` maybe allow switch to take 2 parameters, if the first is a struct with bit fields, the 2nd is the number of bits it bitshifts off the topThat doesn't seem to fit as part of the remit of `switch`, what if there's another field after `i`? Why is it better than `switch (bar.i)`?
Aug 07
On Thursday, 7 August 2025 at 16:35:45 UTC, Nick Treleaven wrote:On Wednesday, 6 August 2025 at 19:00:09 UTC, monkyyy wrote:Its not bar.i[...]That doesn't seem to fit as part of the remit of `switch`, what if there's another field after `i`? Why is it better than `switch (bar.i)`?its `(bar.a<<2 | bar.b<<1 |bar.c)` in a single op that uses no introspection on the contents of bar[...]
Aug 07