mirror of
https://github.com/Neargye/magic_enum.git
synced 2026-01-10 23:44:29 +00:00
parent
785b3f253d
commit
9d1cf196cf
3 changed files with 34 additions and 7 deletions
|
|
@ -330,10 +330,16 @@ constexpr string_view enum_type_name() noexcept;
|
|||
|
||||
```cpp
|
||||
template <typename... Es>
|
||||
[[nodiscard]] constexpr optional<std::uintmax_t> enum_fuse(Es... values);
|
||||
[[nodiscard]] constexpr optional<FusedEnum> enum_fuse(Es... values);
|
||||
```
|
||||
|
||||
* Returns a bijective mix of several enum values. This can be used to emulate 2D switch/case statements.
|
||||
* Returns a typesafe bijective mix of several enum values. This can be used to emulate 2D switch/case statements.
|
||||
|
||||
* Return type is `optional<FusedEnum>` where FusedEnum is an incomplete enum. It is unique for any given combination of `Es...`.
|
||||
|
||||
* Switch/case statement over an incomplete enum is a Visual Studio warning C4064
|
||||
* You have to silent (/wd4064) or ignore it.
|
||||
* Alternatively, define MAGIC_ENUM_NO_TYPESAFE_ENUM_FUSE to disable type-safety (FusedEnum equals std::uintmax_t).
|
||||
|
||||
* Examples
|
||||
|
||||
|
|
@ -341,6 +347,7 @@ template <typename... Es>
|
|||
switch (magic_enum::enum_fuse(color, direction).value()) {
|
||||
case magic_enum::enum_fuse(Color::RED, Directions::Up).value(): // ...
|
||||
case magic_enum::enum_fuse(Color::BLUE, Directions::Down).value(): // ...
|
||||
case magic_enum::enum_fuse(Directions::BLUE, Color::Down).value(): // Compilation error
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue