mirror of
https://github.com/Neargye/magic_enum.git
synced 2026-02-01 03:10:06 +00:00
Add adl_ranges
Co-Authored-By: ZXShady <153229951+ZXShady@users.noreply.github.com> Co-Authored-By: lsemprini <17140216+lsemprini@users.noreply.github.com>
This commit is contained in:
parent
a413fcc9c4
commit
63bbfbc6de
5 changed files with 174 additions and 14 deletions
|
|
@ -23,6 +23,32 @@
|
|||
|
||||
* If an enum is declared as a flag enum, its zero value will not be reflected.
|
||||
|
||||
* Or, for enum types that are deeply nested in classes and/or namespaces, declare a function called `my_adl_info_struct adl_magic_enum_define_range(my_enum_type)` in the same namespace as `my_enum_type`, which magic_enum will find by ADL (because the function is in the same class/namespace as `my_enum_type`), and whose return type is a struct with `static constexpr` data members containing the same parameters as `magic_enum::customize::enum_range<my_enum_type>`
|
||||
```cpp
|
||||
namespace Deeply::Nested::Namespace {
|
||||
enum class my_enum_type { ... };
|
||||
struct my_adl_info_struct {
|
||||
static constexpr bool is_flags = true;
|
||||
// you can also set min and max here (see Enum Range below)
|
||||
// static constexpr int min = ...;
|
||||
// static constexpr int max = ...;
|
||||
};
|
||||
// - magic_enum will find this function by ADL
|
||||
// - no need to ever define this function
|
||||
my_adl_info_struct adl_magic_enum_define_range(my_enum_type);
|
||||
}
|
||||
```
|
||||
|
||||
* As a shorthand, if you only want to set `is_flags` and not `min` or `max`, you can also use `magic_enum::customize::adl_info<is_flags_bool>` to avoid having to define `my_adl_info_struct` in your code:
|
||||
```cpp
|
||||
namespace Deeply::Nested::Namespace {
|
||||
enum class my_enum_type { ... };
|
||||
// - magic_enum will find this function by ADL
|
||||
// - no need to ever define this function
|
||||
magic_enum::customize::adl_info<true> adl_magic_enum_define_range(my_enum_type);
|
||||
}
|
||||
```
|
||||
|
||||
## Enum Range
|
||||
|
||||
* Enum values must be in the range `[MAGIC_ENUM_RANGE_MIN, MAGIC_ENUM_RANGE_MAX]`.
|
||||
|
|
@ -52,6 +78,32 @@
|
|||
};
|
||||
```
|
||||
|
||||
* Or, for enum types that are deeply nested in classes and/or namespaces, declare a function called `my_adl_info_struct adl_magic_enum_define_range(my_enum_type)` in the same namespace as `my_enum_type`, which magic_enum will find by ADL (because the function is in the same class/namespace as `my_enum_type`), and whose return type is a struct with `static constexpr` data members containing the same parameters as `magic_enum::customize::enum_range<my_enum_type>`
|
||||
```cpp
|
||||
namespace Deeply::Nested::Namespace {
|
||||
enum class my_enum_type { ... };
|
||||
struct my_adl_info_struct {
|
||||
static constexpr int min = 100;
|
||||
static constexpr int max = 300;
|
||||
// you can also set is_flags here
|
||||
// static constexpr bool is_flags = true;
|
||||
};
|
||||
// - magic_enum will find this function by ADL
|
||||
// - no need to ever define this function
|
||||
my_adl_info_struct adl_magic_enum_define_range(my_enum_type);
|
||||
}
|
||||
```
|
||||
|
||||
* As a shorthand, if you only want to set `min` and `max` and not `is_flags`, you can also use `magic_enum::customize::adl_info<min_int, max_int>` to avoid having to define `my_adl_info_struct` in your code:
|
||||
```cpp
|
||||
namespace Deeply::Nested::Namespace {
|
||||
enum class my_enum_type { ... };
|
||||
// - magic_enum will find this function by ADL
|
||||
// - no need to ever define this function
|
||||
magic_enum::customize::adl_info<100 /*min*/, 300 /*max*/> adl_magic_enum_define_range(my_enum_type);
|
||||
}
|
||||
```
|
||||
|
||||
## Aliasing
|
||||
|
||||
magic_enum [won't work if a value is aliased](https://github.com/Neargye/magic_enum/issues/68). How magic_enum works with aliases is compiler-implementation-defined.
|
||||
|
|
|
|||
|
|
@ -512,6 +512,32 @@ constexpr bool enum_flags_contains(string_view value, BinaryPredicate p) noexcep
|
|||
magic_enum::enum_flags_test_any(Left|Down|Right, Down|Right); // -> "true"
|
||||
```
|
||||
|
||||
* Or, for enum types that are deeply nested in classes and/or namespaces, declare a function called `my_adl_info_struct adl_magic_enum_define_range(my_enum_type)` in the same namespace as `my_enum_type`, which magic_enum will find by ADL (because the function is in the same class/namespace as `my_enum_type`), and whose return type is a struct with `static constexpr` data members containing the same parameters as `magic_enum::customize::enum_range<my_enum_type>`
|
||||
```cpp
|
||||
namespace Deeply::Nested::Namespace {
|
||||
enum class my_enum_type { ... };
|
||||
struct my_adl_info_struct {
|
||||
static constexpr bool is_flags = true;
|
||||
// you can also set min and max here (see Limitations document)
|
||||
// static constexpr int min = ...;
|
||||
// static constexpr int max = ...;
|
||||
};
|
||||
// - magic_enum will find this function by ADL
|
||||
// - no need to ever define this function
|
||||
my_adl_info_struct adl_magic_enum_define_range(my_enum_type);
|
||||
}
|
||||
```
|
||||
|
||||
* As a shorthand, if you only want to set `is_flags` and not `min` or `max`, you can also use `magic_enum::customize::adl_info<is_flags_bool>` to avoid having to define `my_adl_info_struct` in your code:
|
||||
```cpp
|
||||
namespace Deeply::Nested::Namespace {
|
||||
enum class my_enum_type { ... };
|
||||
// - magic_enum will find this function by ADL
|
||||
// - no need to ever define this function
|
||||
magic_enum::customize::adl_info<true> adl_magic_enum_define_range(my_enum_type);
|
||||
}
|
||||
```
|
||||
|
||||
## `is_unscoped_enum`
|
||||
|
||||
```cpp
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue