mirror of
https://github.com/Neargye/magic_enum.git
synced 2026-01-10 23:44:29 +00:00
update readme
This commit is contained in:
parent
09373fbd6a
commit
39c5ed518d
1 changed files with 21 additions and 4 deletions
25
README.md
25
README.md
|
|
@ -22,11 +22,11 @@
|
||||||
|
|
||||||
Header-only C++17 library provides static reflection for enums, work with any enum type without any macro or boilerplate code.
|
Header-only C++17 library provides static reflection for enums, work with any enum type without any macro or boilerplate code.
|
||||||
* `enum_cast` obtains enum value from string or integer.
|
* `enum_cast` obtains enum value from string or integer.
|
||||||
* `integer_cast` obtains integer value from enum value.
|
* `enum_integer_value` obtains integer value from enum value.
|
||||||
* `enum_value` returns enum value at specified index.
|
* `enum_value` returns enum value at specified index.
|
||||||
* `enum_values` obtains enum value sequence.
|
* `enum_values` obtains enum value sequence.
|
||||||
* `enum_count` returns number of enum values.
|
* `enum_count` returns number of enum values.
|
||||||
* `enum_name` obtains string name from enum value.
|
* `enum_name` returns string name from enum value.
|
||||||
* `enum_names` obtains string enum name sequence.
|
* `enum_names` obtains string enum name sequence.
|
||||||
* `enum_entries` obtains pair (value enum, string enum name) sequence.
|
* `enum_entries` obtains pair (value enum, string enum name) sequence.
|
||||||
* `is_unscoped_enum` checks whether type is an [Unscoped enumeration](https://en.cppreference.com/w/cpp/language/enum#Unscoped_enumeration).
|
* `is_unscoped_enum` checks whether type is an [Unscoped enumeration](https://en.cppreference.com/w/cpp/language/enum#Unscoped_enumeration).
|
||||||
|
|
@ -82,8 +82,8 @@ enum Color { RED = 2, BLUE = 4, GREEN = 8 };
|
||||||
|
|
||||||
* Integer to enum value
|
* Integer to enum value
|
||||||
```cpp
|
```cpp
|
||||||
int color_value = 2;
|
int color_integer = 2;
|
||||||
auto color = magic_enum::enum_cast<Color>(color_value);
|
auto color = magic_enum::enum_cast<Color>(color_integer);
|
||||||
if (colo.has_value()) {
|
if (colo.has_value()) {
|
||||||
// color.value() -> Color::RED
|
// color.value() -> Color::RED
|
||||||
}
|
}
|
||||||
|
|
@ -110,10 +110,18 @@ enum Color { RED = 2, BLUE = 4, GREEN = 8 };
|
||||||
// color -> Color::RED
|
// color -> Color::RED
|
||||||
```
|
```
|
||||||
|
|
||||||
|
* Enum value to integer
|
||||||
|
```cpp
|
||||||
|
Color color = Color::RED;
|
||||||
|
auto color_integer = magic_enum::enum_integer_value(color);
|
||||||
|
// color -> 2
|
||||||
|
```
|
||||||
|
|
||||||
* Enum value sequence
|
* Enum value sequence
|
||||||
```cpp
|
```cpp
|
||||||
constexpr auto colors = magic_enum::enum_values<Color>();
|
constexpr auto colors = magic_enum::enum_values<Color>();
|
||||||
// colors -> {Color::RED, Color::BLUE, Color::GREEN}
|
// colors -> {Color::RED, Color::BLUE, Color::GREEN}
|
||||||
|
// colors[0] -> Color::RED
|
||||||
```
|
```
|
||||||
|
|
||||||
* Number of enum elements
|
* Number of enum elements
|
||||||
|
|
@ -126,6 +134,15 @@ enum Color { RED = 2, BLUE = 4, GREEN = 8 };
|
||||||
```cpp
|
```cpp
|
||||||
constexpr auto color_names = magic_enum::enum_names<Color>();
|
constexpr auto color_names = magic_enum::enum_names<Color>();
|
||||||
// color_names -> {"RED", "BLUE", "GREEN"}
|
// color_names -> {"RED", "BLUE", "GREEN"}
|
||||||
|
// color_names[0] -> "RED"
|
||||||
|
```
|
||||||
|
|
||||||
|
* Enum names sequence
|
||||||
|
```cpp
|
||||||
|
constexpr auto color_entries = magic_enum::enum_entries<Color>();
|
||||||
|
// color_entries -> {{Color::RED, "RED"}, {Color::BLUE, "BLUE"}, {Color::GREEN, "GREEN"}}
|
||||||
|
// color_entries[0].first -> Color::RED
|
||||||
|
// color_entries[0].second -> "RED"
|
||||||
```
|
```
|
||||||
|
|
||||||
* Stream operator for enum
|
* Stream operator for enum
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue