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
c74e53aabe
commit
194e82ed10
1 changed files with 27 additions and 27 deletions
54
README.md
54
README.md
|
|
@ -35,39 +35,39 @@ Header-only C++17 library provides Enum-to-String and String-to-Enum functions.
|
||||||
|
|
||||||
## [Examples](example/example.cpp)
|
## [Examples](example/example.cpp)
|
||||||
|
|
||||||
* Enum to string
|
* Enum variable to string enum name
|
||||||
```cpp
|
```cpp
|
||||||
auto color = Color::RED;
|
auto color = Color::RED;
|
||||||
// Enum variable to string enum name.
|
auto color_name = magic_enum::enum_to_string(color);
|
||||||
auto color_name = magic_enum::enum_to_string(c);
|
if (color_name.has_value()) {
|
||||||
if (color_name.has_value()) {
|
// color_name.value() -> "RED"
|
||||||
// color_name.value() -> "RED"
|
}
|
||||||
}
|
```
|
||||||
|
|
||||||
constexpr auto color = Color::BLUE;
|
* Static storage enum variable to string enum name
|
||||||
// Static storage enum variable to string enum name.
|
```cpp
|
||||||
constexpr auto color_name = magic_enum::enum_to_string<color>();
|
constexpr auto color = Color::BLUE;
|
||||||
if (color_name.has_value()) {
|
constexpr auto color_name = magic_enum::enum_to_string<color>();
|
||||||
// color_name.value() -> "BLUE"
|
if (color_name.has_value()) {
|
||||||
}
|
// color_name.value() -> "BLUE"
|
||||||
```
|
}
|
||||||
|
```
|
||||||
|
|
||||||
* String to enum
|
* String enum name to enum variable
|
||||||
```cpp
|
```cpp
|
||||||
// String enum name to enum variable.
|
constexpr auto color = magic_enum::enum_from_string<Color>("GREEN");
|
||||||
constexpr auto color = magic_enum::enum_from_string<Color>("GREEN");
|
if (color.has_value()) {
|
||||||
if (color.has_value()) {
|
// color.value() -> Color::GREEN
|
||||||
// color.value() -> Color::GREEN
|
}
|
||||||
}
|
```
|
||||||
```
|
|
||||||
|
|
||||||
## Remarks
|
## Remarks
|
||||||
|
|
||||||
* Enum variable must be in range (-MAGIC_ENUM_RANGE, MAGIC_ENUM_RANGE). By default MAGIC_ENUM_RANGE = 128. If you need a larger range, redefine the macro MAGIC_ENUM_RANGE.
|
* Enum variable must be in range (-MAGIC_ENUM_RANGE, MAGIC_ENUM_RANGE). By default MAGIC_ENUM_RANGE = 128. If you need a larger range, redefine the macro MAGIC_ENUM_RANGE.
|
||||||
```cpp
|
```cpp
|
||||||
#define MAGIC_ENUM_RANGE 1028 // Redefine MAGIC_ENUM_RANGE for larger range.
|
#define MAGIC_ENUM_RANGE 1028 // Redefine MAGIC_ENUM_RANGE for larger range.
|
||||||
#include <magic_enum.hpp>
|
#include <magic_enum.hpp>
|
||||||
```
|
```
|
||||||
|
|
||||||
## Integration
|
## Integration
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue