diff --git a/doc/limitations.md b/doc/limitations.md index cc1f8a3..cdd3747 100644 --- a/doc/limitations.md +++ b/doc/limitations.md @@ -50,7 +50,7 @@ Banana = 3, COUNT = 4 }; - // magic_enum::enum_cast("Box") -> std::nullopt + // magic_enum::enum_cast("Box") -> nullopt // magic_enum::enum_name(ShapeKind::Box) -> "ConvexBegin" ``` @@ -76,7 +76,7 @@ // magic_enum::enum_name(ShapeKind::Box) -> "Box" // Non-reflected aliases. - // magic_enum::enum_cast("ConvexBegin") -> std::nullopt + // magic_enum::enum_cast("ConvexBegin") -> nullopt // magic_enum::enum_name(ShapeKind::ConvexBegin) -> "Box" ``` @@ -87,9 +87,9 @@ one = 1, ONE = 1 }; - // magic_enum::enum_cast("one") -> std::nullopt + // magic_enum::enum_cast("one") -> nullopt // magic_enum::enum_name(Number::one) -> "" - // magic_enum::enum_cast("ONE") -> std::nullopt + // magic_enum::enum_cast("ONE") -> nullopt // magic_enum::enum_name(Number::ONE) -> "" ``` diff --git a/doc/reference.md b/doc/reference.md index 944014b..7d1d670 100644 --- a/doc/reference.md +++ b/doc/reference.md @@ -13,7 +13,7 @@ * [`enum_type_name` returns type name of enum.](#enum_type_name) * [`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" std::underlying_type.](#underlying_type) +* [`underlying_type` improved UB-free "SFINAE-friendly" underlying_type.](#underlying_type) * [`ostream_operators` ostream operators for enums.](#ostream_operators) * [`bitwise_operators` bitwise operators for enums.](#bitwise_operators) @@ -41,9 +41,9 @@ constexpr optional enum_cast(string_view value, BinaryPredicate p) noexcept(i * Obtains enum value from string or integer. -* Returns `std::optional`, using `has_value()` to check contains enum value and `value()` to get the enum value. +* Returns `optional`, using `has_value()` to check contains enum value and `value()` to get the enum value. -* If argument does not enum value, returns empty `std::optional`. +* If argument does not enum value, returns empty `optional`. * Examples @@ -93,7 +93,7 @@ template constexpr array enum_values() noexcept; ``` -* Returns `std::array` with all enum values where `N = number of enum values`, sorted by enum value. +* Returns `array` with all enum values where `N = number of enum values`, sorted by enum value. * Examples @@ -146,7 +146,7 @@ template constexpr string_view enum_name() noexcept; ``` -* Returns name from enum value as `std::string_view` with null-terminated string. +* Returns name from enum value as `string_view` with null-terminated string. * If enum value does not have name or [out of range](limitations.md), `enum_name(value)` returns empty string. * If enum value does not have name, `enum_name()` occurs the compilation error `"Enum value does not have a name."`. @@ -177,7 +177,7 @@ template constexpr array enum_names() noexcept; ``` -* Returns `std::array` with all names where `N = number of enum values`, sorted by enum value. +* Returns `array` with all names where `N = number of enum values`, sorted by enum value. * Examples @@ -194,7 +194,7 @@ template constexpr array, N> enum_entries() noexcept; ``` -* Returns `std::array, N>` with all pairs (value, name) where `N = number of enum values`, sorted by enum value. +* Returns `array, N>` with all pairs (value, name) where `N = number of enum values`, sorted by enum value. * Examples @@ -214,7 +214,7 @@ constexpr optional enum_index() noexcept; * Obtains index in enum values from enum value. -* Returns `std::optional` with index. +* Returns `optional` with index. * Examples @@ -261,7 +261,7 @@ template constexpr string_view enum_type_name() noexcept; ``` -* Returns type name of enum as `std::string_view` null-terminated string. +* Returns type name of enum as `string_view` null-terminated string. * Examples @@ -331,7 +331,7 @@ template using underlying_type_t = typename underlying_type::type; ``` -* Improved UB-free "SFINAE-friendly" [std::underlying_type](https://en.cppreference.com/w/cpp/types/underlying_type). +* Improved UB-free "SFINAE-friendly" [underlying_type](https://en.cppreference.com/w/cpp/types/underlying_type). * If T is a complete enumeration type, provides a member typedef type that names the underlying type of T.
Otherwise, if T is not an enumeration type, there is no member type.
diff --git a/include/magic_enum.hpp b/include/magic_enum.hpp index 619eda4..5a5f4b2 100644 --- a/include/magic_enum.hpp +++ b/include/magic_enum.hpp @@ -154,13 +154,20 @@ struct supported : std::false_type {}; #endif +struct char_equal_to { + constexpr bool operator()(char lhs, char rhs) const noexcept { + return lhs == rhs; + } +}; + template -struct static_string { +class static_string { + public: constexpr explicit static_string(string_view str) noexcept : static_string{str, std::make_index_sequence{}} { assert(str.size() == N); } - constexpr const char* data() const noexcept { return chars.data(); } + constexpr const char* data() const noexcept { return chars_.data(); } constexpr std::size_t size() const noexcept { return N; } @@ -168,13 +175,14 @@ struct static_string { private: template - constexpr static_string(string_view str, std::index_sequence) noexcept : chars{{str[I]..., '\0'}} {} + constexpr static_string(string_view str, std::index_sequence) noexcept : chars_{{str[I]..., '\0'}} {} - const std::array chars; + const std::array chars_; }; template <> -struct static_string<0> { +class static_string<0> { + public: constexpr explicit static_string(string_view) noexcept {} constexpr const char* data() const noexcept { return nullptr; } @@ -184,12 +192,6 @@ struct static_string<0> { constexpr operator string_view() const noexcept { return {}; } }; -struct char_equal_to { - constexpr bool operator()(char lhs, char rhs) const noexcept { - return lhs == rhs; - } -}; - constexpr string_view pretty_name(string_view name) noexcept { for (std::size_t i = name.size(); i > 0; --i) { if (!((name[i - 1] >= '0' && name[i - 1] <= '9') ||