Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

@stkw0

Description

@stkw0

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions