mirror of
https://github.com/aantron/better-enums.git
synced 2025-12-06 08:46:42 +08:00
parent
21417b76b9
commit
e5549fb18c
@ -61,7 +61,7 @@ Simply add `enum.h` to your project.
|
||||
|
||||
## Limitations
|
||||
|
||||
The biggest limitation is that the `BETTER_ENUM` macro can't be used inside a
|
||||
1. The biggest limitation is that the `BETTER_ENUM` macro can't be used inside a
|
||||
class. This seems [difficult to remove][nested]. There is a workaround with
|
||||
`typedef` (or C++11 `using`):
|
||||
|
||||
@ -78,11 +78,11 @@ triplet::Color color;
|
||||
|
||||
You can, however, use `BETTER_ENUM` inside a namespace.
|
||||
|
||||
The macro has a soft limit of 64 declared constants. You can extend it by
|
||||
2. The macro has a soft limit of 64 declared constants. You can extend it by
|
||||
following [these instructions][extend]. Ultimately, the number of constants is
|
||||
limited by your compiler's maximum macro argument count.
|
||||
|
||||
In some cases, it is necessary to prefix constants such as `Channel::Red` with a
|
||||
3. In some cases, it is necessary to prefix constants such as `Channel::Red` with a
|
||||
`+` to explicitly promote them to type `Channel`. For example, if you are doing
|
||||
a comparison:
|
||||
|
||||
@ -90,8 +90,11 @@ a comparison:
|
||||
channel == +Channel::Red
|
||||
```
|
||||
|
||||
4. On msvc, you may need to enable [warning C4062][C4062] to get `switch` case exhaustiveness checking.
|
||||
|
||||
[nested]: http://aantron.github.io/better-enums/DesignDecisionsFAQ.html#NoEnumInsideClass
|
||||
[extend]: http://aantron.github.io/better-enums/ExtendingLimits.html
|
||||
[C4062]: https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-4-c4062
|
||||
|
||||
<br/>
|
||||
|
||||
|
||||
@ -21,6 +21,10 @@ A Better Enum can be used directly in a `switch` statement:
|
||||
If you miss a case or add a redundant one, your compiler should be able to give
|
||||
you a warning — try it!
|
||||
|
||||
Note that on msvc, you may need to enable [warning C4062][C4062].
|
||||
|
||||
[C4062]: https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-4-c4062
|
||||
|
||||
---
|
||||
|
||||
std::cout << n << std::endl;
|
||||
|
||||
@ -22,6 +22,8 @@ int main()
|
||||
|
||||
// If you miss a case or add a redundant one, your compiler should be able to
|
||||
// give you a warning - try it!
|
||||
//
|
||||
// Note that on msvc, you may need to enable warning C4062.
|
||||
|
||||
|
||||
std::cout << n << std::endl;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user