Neargye / magic_enum

Static reflection for enums (to string, from string, iteration) for modern C++, work with any enum type without any macro or boilerplate code
MIT License
4.76k stars 422 forks source link

enum_contains occur error when number excceed 127 #345

Closed yuekeyuans closed 4 months ago

yuekeyuans commented 4 months ago
enum class A {
    a = 127,
    b = 128
};

int main()
{
    std::cout << magic_enum::enum_contains<A>(127);    // output 1
    std::cout << magic_enum::enum_contains<A>(128);    // output 0
}

as above, the second line out put ought to be 1(true), but produce 0 (false) value.

can you fix this bug?

alexkaratarakis commented 4 months ago

By default, only values within [-128, 127] are visible to magic_enum. More info here: https://github.com/Neargye/magic_enum/blob/master/doc/limitations.md#enum-range You can customize the allowed range globally (for all enums) or for each enum individually.

yuekeyuans commented 4 months ago

thank you, I see it. this really helps me a lot