mirror of
https://github.com/Neargye/magic_enum.git
synced 2026-01-09 23:34:23 +00:00
parent
596f00c0db
commit
8bd403f888
10 changed files with 502 additions and 298 deletions
|
|
@ -6,7 +6,6 @@
|
|||
* [`enum_count` returns number of enum values.](#enum_count)
|
||||
* [`enum_integer` obtains integer value from enum value.](#enum_integer)
|
||||
* [`enum_name` returns name from enum value.](#enum_name)
|
||||
* [`enum_flags_name` returns name from enum-flags value.](#enum_flags_name)
|
||||
* [`enum_names` obtains string enum name sequence.](#enum_names)
|
||||
* [`enum_entries` obtains pair (value enum, string enum name) sequence.](#enum_entries)
|
||||
* [`enum_index` obtains index in enum value sequence from enum value.](#enum_index)
|
||||
|
|
@ -15,6 +14,7 @@
|
|||
* [`enum_fuse` returns a bijective mix of enum values.](#enum_fuse)
|
||||
* [`enum_switch` allows runtime enum value transformation to constexpr context.](#enum_switch)
|
||||
* [`enum_for_each` calls a function with all enum constexpr value.](#enum_for_each)
|
||||
* [`enum_flags` API from enum-flags.](#enum_flags)
|
||||
* [`is_unscoped_enum` checks whether type is an Unscoped enumeration.](#is_unscoped_enum)
|
||||
* [`is_scoped_enum` checks whether type is an Scoped enumeration.](#is_scoped_enum)
|
||||
* [`underlying_type` improved UB-free "SFINAE-friendly" underlying_type.](#underlying_type)
|
||||
|
|
@ -219,25 +219,6 @@ constexpr string_view enum_name() noexcept;
|
|||
// color_name -> "BLUE"
|
||||
```
|
||||
|
||||
## `enum_flags_name`
|
||||
|
||||
```cpp
|
||||
template <typename E>
|
||||
string enum_flags_name(E value);
|
||||
```
|
||||
|
||||
* Returns name from enum-flags value as `string` with null-terminated string.
|
||||
|
||||
* If enum-flags value does not have name or [out of range](limitations.md), returns empty string.
|
||||
|
||||
* Examples
|
||||
|
||||
```cpp
|
||||
auto directions_name = magic_enum::enum_flags_name(Directions::Up | Directions::Right);
|
||||
// directions_name -> "Directions::Up | Directions::Right"
|
||||
```
|
||||
|
||||
|
||||
## `enum_names`
|
||||
|
||||
```cpp
|
||||
|
|
@ -383,20 +364,21 @@ constexpr Result enum_switch(Lambda&& lambda, E value);
|
|||
|
||||
template <typename Result, typename E, typename Lambda>
|
||||
constexpr Result enum_switch(Lambda&& lambda, E value, Result&& result);
|
||||
|
||||
template <typename E, typename Result = void, typename BinaryPredicate = std::equal_to<>, typename Lambda>
|
||||
constexpr Result enum_switch(Lambda&& lambda, string_view name, BinaryPredicate&& p = {});
|
||||
|
||||
template <typename E, typename Result, typename BinaryPredicate = std::equal_to<>, typename Lambda>
|
||||
constexpr Result enum_switch(Lambda&& lambda, string_view name, Result&& result, BinaryPredicate&& p = {});
|
||||
|
||||
template <typename E, typename Result = void, typename Lambda>
|
||||
constexpr Result enum_switch(Lambda&& lambda, underlying_type_t<E> value);
|
||||
|
||||
template <typename E, typename Result, typename Lambda>
|
||||
constexpr Result enum_switch(Lambda&& lambda, underlying_type_t<E> value, Result&& result);
|
||||
```
|
||||
|
||||
* You should add the required file `<magic_enum_switch.hpp>`.
|
||||
|
||||
* Examples
|
||||
|
||||
```cpp
|
||||
Color color = Color::RED;
|
||||
|
||||
magic_enum::enum_switch([] (auto val) {
|
||||
constexpr Color c_color = val;
|
||||
// ...
|
||||
}, color);
|
||||
```
|
||||
|
||||
## `enum_for_each`
|
||||
|
||||
```cpp
|
||||
|
|
@ -404,6 +386,51 @@ template <typename E, typename Lambda>
|
|||
constexpr auto enum_for_each(Lambda&& lambda);
|
||||
```
|
||||
|
||||
* Examples
|
||||
|
||||
```cpp
|
||||
magic_enum::enum_for_each<Color>([] (auto val) {
|
||||
constexpr Color c_color = val;
|
||||
// ...
|
||||
});
|
||||
```
|
||||
|
||||
## `enum_flags`
|
||||
|
||||
```cpp
|
||||
template <typename E>
|
||||
string enum_flags_name(E value);
|
||||
|
||||
template <typename E>
|
||||
constexpr optional<E> enum_flags_cast(underlying_type_t<E> value) noexcept;
|
||||
|
||||
template <typename E>
|
||||
constexpr optional<E> enum_flags_cast(string_view value) noexcept;
|
||||
|
||||
template <typename E, typename BinaryPredicate>
|
||||
constexpr optional<E> enum_flags_cast(string_view value, BinaryPredicate p) noexcept(is_nothrow_invocable_v<BinaryPredicate>);
|
||||
|
||||
template <typename E>
|
||||
constexpr bool enum_flags_contains(E value) noexcept;
|
||||
|
||||
template <typename E>
|
||||
constexpr bool enum_flags_contains(underlying_type_t<E> value) noexcept;
|
||||
|
||||
template <typename E>
|
||||
constexpr bool enum_flags_contains(string_view value) noexcept;
|
||||
|
||||
template <typename E, typename BinaryPredicate>
|
||||
constexpr optional<E> enum_flags_contains(string_view value, BinaryPredicate p) noexcept(is_nothrow_invocable_v<BinaryPredicate>);
|
||||
```
|
||||
|
||||
* Examples
|
||||
|
||||
```cpp
|
||||
auto directions_name = magic_enum::enum_flags_name(Directions::Up | Directions::Right);
|
||||
// directions_name -> "Directions::Up | Directions::Right"
|
||||
```
|
||||
|
||||
|
||||
## `is_unscoped_enum`
|
||||
|
||||
```cpp
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue