mirror of
https://github.com/Neargye/magic_enum.git
synced 2026-01-09 23:34:23 +00:00
add constexpr containers (#187)
This commit is contained in:
parent
2a7658d084
commit
533c9509ef
10 changed files with 2609 additions and 7 deletions
37
README.md
37
README.md
|
|
@ -42,6 +42,9 @@ Header-only C++17 library provides static reflection for enums, work with any en
|
|||
* `underlying_type` improved UB-free "SFINAE-friendly" [underlying_type](https://en.cppreference.com/w/cpp/types/underlying_type).
|
||||
* `ostream_operators` ostream operators for enums.
|
||||
* `bitwise_operators` bitwise operators for enums.
|
||||
* `containers::array` array container for enums.
|
||||
* `containers::bitset` bitset container for enums.
|
||||
* `containers::set` set container for enums.
|
||||
|
||||
## Documentation
|
||||
|
||||
|
|
@ -222,6 +225,40 @@ Header-only C++17 library provides static reflection for enums, work with any en
|
|||
// color_name -> "BLUE"
|
||||
```
|
||||
|
||||
* `containers::array` array container for enums.
|
||||
|
||||
```cpp
|
||||
magic_enum::containers::array<Color, RGB> color_rgb_array {};
|
||||
color_rgb_array[Color::RED] = {255, 0, 0};
|
||||
color_rgb_array[Color::GREEN] = {0, 255, 0};
|
||||
color_rgb_array[Color::BLUE] = {0, 0, 255};
|
||||
std::get<Color::BLUE>(color_rgb_array) // -> RGB{0, 0, 255}
|
||||
```
|
||||
|
||||
* `containers::bitset` bitset container for enums.
|
||||
|
||||
```cpp
|
||||
constexpr magic_enum::containers::bitset<Color> color_bitset_red_green {Color::RED|Color::GREEN};
|
||||
bool all = color_bitset_red_green.all();
|
||||
// all -> false
|
||||
// Color::BLUE is missing
|
||||
bool test = color_bitset_red_green.test(Color::RED);
|
||||
// test -> true
|
||||
```
|
||||
|
||||
* `containers::set` set container for enums.
|
||||
|
||||
```cpp
|
||||
auto color_set = magic_enum::containers::set<Color>();
|
||||
bool empty = color_set.empty();
|
||||
// empty -> true
|
||||
color_set.insert(Color::GREEN);
|
||||
color_set.insert(Color::BLUE);
|
||||
color_set.insert(Color::RED);
|
||||
std::size_t size = color_set.size();
|
||||
// size -> 3
|
||||
```
|
||||
|
||||
## Remarks
|
||||
|
||||
* `magic_enum` does not pretend to be a silver bullet for reflection for enums, it was originally designed for small enum.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue