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

update comments

This commit is contained in:
neargye 2020-11-08 22:00:23 +02:00
parent caa2f9e6ef
commit ae7aabf63d
2 changed files with 13 additions and 13 deletions

View file

@ -36,9 +36,9 @@ constexpr std::string_view magic_enum::customize::enum_name<Color>(Color value)
case Color::BLUE: case Color::BLUE:
return "The BLUE"; return "The BLUE";
case Color::GREEN: case Color::GREEN:
return {}; // "Empty string for default value." return {}; // Empty string for default value.
} }
return {}; // "Empty string for unknow value." return {}; // Empty string for unknow value.
} }
enum class Numbers : int { One, Two, Three }; enum class Numbers : int { One, Two, Three };
@ -51,21 +51,21 @@ constexpr std::string_view magic_enum::customize::enum_name<Numbers>(Numbers val
case Numbers::One: case Numbers::One:
return "the one"; return "the one";
default: default:
return {}; // "Empty string for default or unknow value." return {}; // Empty string for default or unknow value.
} }
} }
int main() { int main() {
std::cout << magic_enum::enum_name(Color::RED) << std::endl; // "the red color" std::cout << magic_enum::enum_name(Color::RED) << std::endl; // the red color
std::cout << magic_enum::enum_name(Color::BLUE) << std::endl; // "The BLUE" std::cout << magic_enum::enum_name(Color::BLUE) << std::endl; // The BLUE
std::cout << magic_enum::enum_name(Color::GREEN) << std::endl; // "GREEN" std::cout << magic_enum::enum_name(Color::GREEN) << std::endl; // GREEN
std::cout << std::boolalpha; std::cout << std::boolalpha;
std::cout << (magic_enum::enum_cast<Color>("the red color").value() == Color::RED) << std::endl; // "true" std::cout << (magic_enum::enum_cast<Color>("the red color").value() == Color::RED) << std::endl; // true
std::cout << magic_enum::enum_name(Numbers::One) << std::endl; // "the one" std::cout << magic_enum::enum_name(Numbers::One) << std::endl; // the one
std::cout << magic_enum::enum_name(Numbers::Two) << std::endl; // "Two" std::cout << magic_enum::enum_name(Numbers::Two) << std::endl; // Two
std::cout << magic_enum::enum_name(Numbers::Three) << std::endl; // "Three" std::cout << magic_enum::enum_name(Numbers::Three) << std::endl; // Three
return 0; return 0;
} }

View file

@ -99,14 +99,14 @@ template <typename T>
using optional = std::optional<T>; using optional = std::optional<T>;
#endif #endif
// If need another optional type, define the macro MAGIC_ENUM_USING_ALIAS_STRING_VIEW. // If need another string_view type, define the macro MAGIC_ENUM_USING_ALIAS_STRING_VIEW.
#if defined(MAGIC_ENUM_USING_ALIAS_STRING_VIEW) #if defined(MAGIC_ENUM_USING_ALIAS_STRING_VIEW)
MAGIC_ENUM_USING_ALIAS_STRING_VIEW MAGIC_ENUM_USING_ALIAS_STRING_VIEW
#else #else
using string_view = std::string_view; using string_view = std::string_view;
#endif #endif
// If need another optional type, define the macro MAGIC_ENUM_USING_ALIAS_STRING. // If need another string type, define the macro MAGIC_ENUM_USING_ALIAS_STRING.
#if defined(MAGIC_ENUM_USING_ALIAS_STRING) #if defined(MAGIC_ENUM_USING_ALIAS_STRING)
MAGIC_ENUM_USING_ALIAS_STRING MAGIC_ENUM_USING_ALIAS_STRING
#else #else
@ -134,7 +134,7 @@ static_assert(MAGIC_ENUM_RANGE_MAX < (std::numeric_limits<std::int16_t>::max)(),
static_assert(MAGIC_ENUM_RANGE_MAX > MAGIC_ENUM_RANGE_MIN, "MAGIC_ENUM_RANGE_MAX must be greater than MAGIC_ENUM_RANGE_MIN."); static_assert(MAGIC_ENUM_RANGE_MAX > MAGIC_ENUM_RANGE_MIN, "MAGIC_ENUM_RANGE_MAX must be greater than MAGIC_ENUM_RANGE_MIN.");
// If need cunstom names for enum type, add specialization enum_name for necessary enum type. // If need cunstom names for enum, add specialization enum_name for necessary enum type.
template <typename E> template <typename E>
constexpr string_view enum_name(E) noexcept { constexpr string_view enum_name(E) noexcept {
static_assert(std::is_enum_v<E>, "magic_enum::customize::enum_name requires enum type."); static_assert(std::is_enum_v<E>, "magic_enum::customize::enum_name requires enum type.");