mirror of
https://github.com/Neargye/magic_enum.git
synced 2026-01-09 23:34:23 +00:00
update comments
This commit is contained in:
parent
caa2f9e6ef
commit
ae7aabf63d
2 changed files with 13 additions and 13 deletions
|
|
@ -36,9 +36,9 @@ constexpr std::string_view magic_enum::customize::enum_name<Color>(Color value)
|
|||
case Color::BLUE:
|
||||
return "The BLUE";
|
||||
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 };
|
||||
|
|
@ -51,21 +51,21 @@ constexpr std::string_view magic_enum::customize::enum_name<Numbers>(Numbers val
|
|||
case Numbers::One:
|
||||
return "the one";
|
||||
default:
|
||||
return {}; // "Empty string for default or unknow value."
|
||||
return {}; // Empty string for default or unknow value.
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
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::GREEN) << std::endl; // "GREEN"
|
||||
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::GREEN) << std::endl; // GREEN
|
||||
|
||||
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::Two) << std::endl; // "Two"
|
||||
std::cout << magic_enum::enum_name(Numbers::Three) << std::endl; // "Three"
|
||||
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::Three) << std::endl; // Three
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -99,14 +99,14 @@ template <typename T>
|
|||
using optional = std::optional<T>;
|
||||
#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)
|
||||
MAGIC_ENUM_USING_ALIAS_STRING_VIEW
|
||||
#else
|
||||
using string_view = std::string_view;
|
||||
#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)
|
||||
MAGIC_ENUM_USING_ALIAS_STRING
|
||||
#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.");
|
||||
|
||||
// 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>
|
||||
constexpr string_view enum_name(E) noexcept {
|
||||
static_assert(std::is_enum_v<E>, "magic_enum::customize::enum_name requires enum type.");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue