With the bitset enum, the example doesn't show how to convert to and from integers and I couldn't find any code online that does this. There's a to_ulong() function but I have no idea what the parameter for that is.
Isn't the whole point of a bitset enum that you can get and set integers? Otherwise it's just a set?
namespace foo {
enum class Color { RED = 1, GREEN = 2, BLUE = 4 };
} // namespace -> // is_flags has to be done from global namespace between definition and first use
template <>
struct magic_enum::customize::enum_range<Color> {
static constexpr bool is_flags = true;
};
namespace foo {
void main() {
auto color_bitset = magic_enum::containers::bitset<Color>();
color_bitset.set(3);
std::cout << color_bitset << std::endl; // RED|GREEN
int val = color_bitset.to_number(); // 3!
}
} // namespace
That's my use case and why I looked more into magic_enum. Some embedded thing sends me a byte full of flags and I want to code as though what it meant was flags.test(Flags::SLOW_CLOCK) and reply with flags.set(Flags::FAST_CLOCK)?
More generally, it would be handy if the examples directory covered every public method on the type rather than just the trivial cases.
With the bitset enum, the example doesn't show how to convert to and from integers and I couldn't find any code online that does this. There's a to_ulong() function but I have no idea what the parameter for that is.
Isn't the whole point of a bitset enum that you can get and set integers? Otherwise it's just a set?
That's my use case and why I looked more into magic_enum. Some embedded thing sends me a byte full of flags and I want to code as though what it meant was flags.test(Flags::SLOW_CLOCK) and reply with flags.set(Flags::FAST_CLOCK)?
More generally, it would be handy if the examples directory covered every public method on the type rather than just the trivial cases.