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.88k stars 434 forks source link

[Feature request] add support for something like std::in_range for eums #355

Closed stkw0 closed 3 months ago

stkw0 commented 4 months ago

Use case

I have a binary data file which I read into a struct. This struct has some enum class, but there is a small possibility that the data readed is incorrect or corrupted, which would result in values out of the range.

Request

With C++20 we have std::in_range. One possibility would be for me to implement the needed operators to use std::in_range or add a enum value called "MAX_VALUE" or alike and check all enum values are less than that. Also, magic_enum has magic_enum::enum_contains which could be used for this purposes. But still, the API seems to be designed for a different use case, so I think it could be useful to add an API for validating an enum.

Thank you very much

Neargye commented 3 months ago

added enum_reflected, which work as std::in_range