Skip to content

Commit

Permalink
update usage
Browse files Browse the repository at this point in the history
  • Loading branch information
mguludag committed Mar 11, 2024
1 parent 9e96a10 commit 8f5937d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ namespace mgutility{
namespace detail{
// specialize rgb_color::unknown to make output "UNKNOWN"
template <>
constexpr inline auto enum_type::name<rgb_color, rgb_color::unknown>() noexcept -> string_view { return "UNKNOWN"; }
constexpr inline auto enum_type::name<rgb_color, rgb_color::unknown>() noexcept
-> string_view { return "UNKNOWN"; }
}

template<>
Expand All @@ -51,6 +52,12 @@ int main()
{
auto x = rgb_color::blue;
auto y = mgutility::to_enum<rgb_color>("greenn");

for (auto&& e : mgutility::enum_for_each<rgb_color>()) {
std::cout << e.name << " " << e.to_underlying() << '\n';
// enum_pair<Enum> has two data members: name and value
// to_underlying() converts into underlying type of enum
}

// default signature: enum_name<min_value = -128, max_value = 128, Enum typename>(Enum&&)
// Changing max_value to not too much greater than enum's max value, it will compiles faster
Expand Down

0 comments on commit 8f5937d

Please sign in to comment.