You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/limitations.md
+52Lines changed: 52 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,6 +23,32 @@
23
23
24
24
* If an enum is declared as a flag enum, its zero value will not be reflected.
25
25
26
+
* 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>`
27
+
```cpp
28
+
namespace Deeply::Nested::Namespace {
29
+
enum class my_enum_type { ... };
30
+
struct my_adl_info_struct {
31
+
static constexpr bool is_flags = true;
32
+
// you can also set min and max here (see Enum Range below)
* 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:
* Enum values must be in the range `[MAGIC_ENUM_RANGE_MIN, MAGIC_ENUM_RANGE_MAX]`.
@@ -52,6 +78,32 @@
52
78
};
53
79
```
54
80
81
+
* 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>`
* 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:
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.
* 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>`
516
+
```cpp
517
+
namespace Deeply::Nested::Namespace {
518
+
enum class my_enum_type { ... };
519
+
struct my_adl_info_struct {
520
+
static constexpr bool is_flags = true;
521
+
// you can also set min and max here (see Limitations document)
* 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:
structadl_info { static_assert(sizeof...(Vs) && !sizeof...(Vs), "adl_info parameter types must be either 2 ints exactly or 1 bool for the is_flgas"); };
187
+
188
+
template<int Min, int Max>
189
+
structadl_info<Min, Max> {
190
+
staticconstexprint min = Min;
191
+
staticconstexprint max = Max;
192
+
};
193
+
194
+
template<bool IsFlags>
195
+
structadl_info<IsFlags> {
196
+
staticconstexprbool is_flags = IsFlags;
197
+
};
198
+
168
199
// 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 = 127.
169
200
// If need another range for all enum types by default, redefine the macro MAGIC_ENUM_RANGE_MIN and MAGIC_ENUM_RANGE_MAX.
170
201
// If need another range for specific enum type, add specialization enum_range for necessary enum type.
171
-
template <typename E>
202
+
template <typename E, typename = void>
172
203
structenum_range {
173
-
staticconstexprint min = MAGIC_ENUM_RANGE_MIN;
174
-
staticconstexprint max = MAGIC_ENUM_RANGE_MAX;
204
+
staticconstexprint min = MAGIC_ENUM_RANGE_MIN;
205
+
staticconstexprint max = MAGIC_ENUM_RANGE_MAX;
206
+
};
207
+
208
+
template <typename E>
209
+
structenum_range < E, decltype(void(adl_magic_enum_define_range(E{}))) > {
210
+
staticconstexprint min = detail::has_minmax_adl<E>.first;
211
+
staticconstexprint max = detail::has_minmax_adl<E>.second;
0 commit comments