mirror of
https://github.com/Neargye/magic_enum.git
synced 2026-01-10 23:44:29 +00:00
Add adl_ranges (#413)
Co-authored-by: lsemprini <17140216+lsemprini@users.noreply.github.com>
This commit is contained in:
parent
513e606d7b
commit
d642b05dcb
5 changed files with 174 additions and 14 deletions
|
|
@ -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