1
0
Fork 0
mirror of https://github.com/Neargye/magic_enum.git synced 2026-01-09 23:34:23 +00:00

update doc

This commit is contained in:
terik23 2019-04-04 11:01:17 +05:00
parent 6e9fdcc6da
commit 48e70234b5
2 changed files with 9 additions and 9 deletions

View file

@ -21,8 +21,8 @@
## What is Magic Enum?
Header-only C++17 library provides Enum-to-String and String-to-Enum functions.
* `magic_enum::enum_to_string` used to obtain string enum name from enum variable.
* `magic_enum::enum_from_string` used to obtain enum variable from enum string name.
* `magic_enum::enum_to_string` obtains string enum name from enum variable.
* `magic_enum::enum_from_string` obtains enum variable from enum string name.
## Features
@ -63,11 +63,11 @@ Header-only C++17 library provides Enum-to-String and String-to-Enum functions.
## Remarks
* `magic_enum::enum_to_string` return `std::optional<std::string_view>`, using `has_value()` to check contain enum name and `value()` to get enum name. If enum variable does not have name or out of range `MAGIC_ENUM_RANGE` return `std::nullopt`.
* `magic_enum::enum_to_string` returns `std::optional<std::string_view>`, using `has_value()` to check contains enum name and `value()` to get the enum name. If enum variable does not have name or out of range `MAGIC_ENUM_RANGE`, returns `std::nullopt`.
* `magic_enum::enum_from_string` return `std::optional<E>`, using `has_value()` to check contain enum variable and `value(`) to get enum variable. If enum variable does not have name or out of range `MAGIC_ENUM_RANGE` return `std::nullopt`.
* `magic_enum::enum_from_string` returns `std::optional<E>`, using `has_value()` to check contains enum variable and `value()` to get the enum variable. If enum variable does not have name or out of range `MAGIC_ENUM_RANGE`, returns `std::nullopt`.
* 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 larger range, redefine the macro `MAGIC_ENUM_RANGE`.
```cpp
#define MAGIC_ENUM_RANGE 1028 // Redefine MAGIC_ENUM_RANGE for larger range.
#include <magic_enum.hpp>
@ -75,7 +75,7 @@ Header-only C++17 library provides Enum-to-String and String-to-Enum functions.
## Integration
You have to add required file [magic_enum.hpp](include/magic_enum.hpp).
You should add the required file [magic_enum.hpp](include/magic_enum.hpp).
## Compiler compatibility

View file

@ -166,7 +166,7 @@ struct enum_from_string_impl_t<E, MAGIC_ENUM_RANGE> final {
} // namespace detail
// enum_to_string(enum) used to obtain string enum name from enum variable.
// enum_to_string(enum) obtains string enum name from enum variable.
template <typename T, typename = std::enable_if_t<std::is_enum_v<std::decay_t<T>>>>
[[nodiscard]] constexpr std::optional<std::string_view> enum_to_string(T value) noexcept {
constexpr bool s = std::is_signed_v<std::underlying_type_t<std::decay_t<T>>>;
@ -177,13 +177,13 @@ template <typename T, typename = std::enable_if_t<std::is_enum_v<std::decay_t<T>
return detail::enum_to_string_impl_t<std::decay_t<T>, min>{}(static_cast<int>(value));
}
// enum_to_string<enum>() used to obtain string enum name from static storage enum variable
// enum_to_string<enum>() obtains string enum name from static storage enum variable.
template <auto V, typename = std::enable_if_t<std::is_enum_v<std::decay_t<decltype(V)>>>>
[[nodiscard]] constexpr std::optional<std::string_view> enum_to_string() noexcept {
return detail::enum_to_string_impl<decltype(V), V>();
}
// enum_from_string(name) used to obtain enum variable from enum string name.
// enum_from_string(name) obtains enum variable from enum string name.
template <typename E, typename = std::enable_if_t<std::is_enum_v<E>>>
[[nodiscard]] constexpr std::optional<E> enum_from_string(std::string_view name) noexcept {
constexpr bool s = std::is_signed_v<std::underlying_type_t<E>>;