mirror of
https://github.com/Neargye/magic_enum.git
synced 2026-01-10 23:44:29 +00:00
enum_integer_value -> enum_integer
This commit is contained in:
parent
39c5ed518d
commit
8f095f8c22
3 changed files with 13 additions and 13 deletions
16
README.md
16
README.md
|
|
@ -22,10 +22,10 @@
|
||||||
|
|
||||||
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.
|
||||||
* `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_integer` obtains integer value from enum value.
|
||||||
* `enum_name` returns 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.
|
||||||
|
|
@ -110,13 +110,6 @@ 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>();
|
||||||
|
|
@ -130,6 +123,13 @@ enum Color { RED = 2, BLUE = 4, GREEN = 8 };
|
||||||
// color_count -> 3
|
// color_count -> 3
|
||||||
```
|
```
|
||||||
|
|
||||||
|
* Enum value to integer
|
||||||
|
```cpp
|
||||||
|
Color color = Color::RED;
|
||||||
|
auto color_integer = magic_enum::enum_integer(color);
|
||||||
|
// color -> 2
|
||||||
|
```
|
||||||
|
|
||||||
* Enum names sequence
|
* Enum names sequence
|
||||||
```cpp
|
```cpp
|
||||||
constexpr auto color_names = magic_enum::enum_names<Color>();
|
constexpr auto color_names = magic_enum::enum_names<Color>();
|
||||||
|
|
|
||||||
|
|
@ -54,9 +54,9 @@ int main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enum value to integer value.
|
// Enum value to integer value.
|
||||||
auto color_integer_value = magic_enum::enum_integer_value(Color::RED);
|
auto color_integer = magic_enum::enum_integer(Color::RED);
|
||||||
if (color_integer_value == static_cast<std::underlying_type_t<Color>>(Color::RED)) {
|
if (color_integer == static_cast<std::underlying_type_t<Color>>(Color::RED)) {
|
||||||
std::cout << "RED = " << color_integer_value << std::endl; // RED = -10
|
std::cout << "RED = " << color_integer << std::endl; // RED = -10
|
||||||
}
|
}
|
||||||
|
|
||||||
using namespace magic_enum::ops; // out-of-the-box stream operator for enums.
|
using namespace magic_enum::ops; // out-of-the-box stream operator for enums.
|
||||||
|
|
|
||||||
|
|
@ -245,9 +245,9 @@ template <typename E, typename = detail::enable_if_enum_t<E>>
|
||||||
|
|
||||||
// Returns integer value from enum value.
|
// Returns integer value from enum value.
|
||||||
template <typename E, typename = detail::enable_if_enum_t<E>>
|
template <typename E, typename = detail::enable_if_enum_t<E>>
|
||||||
[[nodiscard]] constexpr auto enum_integer_value(E value) noexcept {
|
[[nodiscard]] constexpr auto enum_integer(E value) noexcept {
|
||||||
using D = std::decay_t<E>;
|
using D = std::decay_t<E>;
|
||||||
static_assert(std::is_enum_v<D>, "magic_enum::enum_integer_value requires enum type.");
|
static_assert(std::is_enum_v<D>, "magic_enum::enum_integer requires enum type.");
|
||||||
|
|
||||||
return static_cast<std::underlying_type_t<D>>(value);
|
return static_cast<std::underlying_type_t<D>>(value);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue