Open JWCS opened 1 month ago
BOTH (/): 0
- https://github.com/Neargye/magic_enum/issues/314#issuecomment-1812285880. BOTH
is not true flag, it is a "flag or"
NONE (/): 0
- https://github.com/Neargye/magic_enum/issues/321
NONE|CCW (/): 0
- will check, looks like bug, expected 1
With respect to the first one, BOTH, the reason for my confusion is that the read() function attempts both (in order) enum_flags_cast and then enum_cast. As per the relevant docs/comment in 314:
enum class TestEnum {
A = 0,
B = 1,
C = 2,
D = 3,
};
enum_name(TestEnum::D) = 'D'; vs enum_flags_name(TestEnum::D) = 'B|C';
enum_flags_cast('A') = nullopt; vs enum_cast('A') = TestEnum::A;
enum_flags_cast('D') = nullopt; vs enum_flags_cast('B|C') = TestEnum::D; vs enum_cast('D') = TestEnum::D;
I'd expect enum_flags_cast('D' /* BOTH */).value_or( enum_cast('D')
to fail on flag-cast D (since not a real flag), but then trying to normal enum cast D to work (enum_cast('D') == TestEnum::D) (and the resulting integer TestEnum::D == TestEnum::B | TestEnum::C).
I tried it like this, such that if the string 'B|C' was passed, that would first get correctly parsed/handled, but if the shorthand 'BOTH' was passed, that would also get correctly handled.
My main question is, is there something I'm missing, that test("BOTH")
->
enum_flags_cast("BOTH") /* fail */ .value_or( enum_cast("BOTH") /* fail */ .value_or("NONE") /* incorrect!? */ )
.
Does it have something to do with
template <>
struct magic_enum::customize::enum_range<FlowDirection> {
static constexpr bool is_flags = true;
};
?
I believe this is related to #314 and #321, so my apologies if it is. But, from the docs and those comments, it almost seemed like the below use case should work; but it fails for the BOTH case. This is after I considered your casting comments in 314 about enum vs enum_flags, and accounted for both input formats, to try both in what seemed the least restrictive way. I also read through the limitations... so I am very confused. Working off of head (0.9.6):
Which results in incorrect values definitely for BOTH, and a curious non-parsing (?) for "NONE|CCW"