mirror of
https://github.com/Neargye/magic_enum.git
synced 2026-01-10 23:44:29 +00:00
New enum-flags API (#120)
This commit is contained in:
parent
6a1db3b8b6
commit
aecf0db795
7 changed files with 336 additions and 477 deletions
|
|
@ -7,6 +7,13 @@
|
|||
|
||||
* Enum can't reflect if the enum is a forward declaration.
|
||||
|
||||
* For enum-flags add specialization `is_flags_enum` for necessary enum type. Specialization of `is_flags_enum` must be injected in `namespace magic_enum::customize`.
|
||||
```cpp
|
||||
enum class Directions { Up = 1 << 1, Down = 1 << 2, Right = 1 << 3, Left = 1 << 4 };
|
||||
template <>
|
||||
struct magic_enum::customize::is_flags_enum<Directions> : std::true_type {};
|
||||
```
|
||||
|
||||
* Enum value must be in range `[MAGIC_ENUM_RANGE_MIN, MAGIC_ENUM_RANGE_MAX]`.
|
||||
|
||||
* By default `MAGIC_ENUM_RANGE_MIN = -128`, `MAGIC_ENUM_RANGE_MAX = 128`.
|
||||
|
|
@ -28,14 +35,12 @@
|
|||
|
||||
enum class number { one = 100, two = 200, three = 300 };
|
||||
|
||||
namespace magic_enum::customize {
|
||||
template <>
|
||||
struct enum_range<number> {
|
||||
struct magic_enum::customize::enum_range<number> {
|
||||
static constexpr int min = 100;
|
||||
static constexpr int max = 300;
|
||||
// (max - min) must be less than UINT16_MIN.
|
||||
};
|
||||
} // namespace magic_enum
|
||||
```
|
||||
|
||||
* `magic_enum` [won't work if a value is aliased](https://github.com/Neargye/magic_enum/issues/68). Work with enum-aliases is compiler-implementation-defined.
|
||||
|
|
|
|||
|
|
@ -24,8 +24,6 @@
|
|||
* To check is magic_enum supported compiler use macro `MAGIC_ENUM_SUPPORTED` or constexpr constant `magic_enum::is_magic_enum_supported`.</br>
|
||||
If magic_enum used on unsupported compiler, occurs the compilation error. To suppress error define macro `MAGIC_ENUM_NO_CHECK_SUPPORT`.
|
||||
|
||||
* For the small enum use the API from the namespace `magic_enum`, and for enum-flags use the API from the namespace `magic_enum::flags`.
|
||||
|
||||
* To add custom enum or type names see the [example](../example/example_custom_name.cpp).
|
||||
|
||||
* To change the type of strings or ortional, use special macros:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue