Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
mguludag authored Mar 3, 2024
1 parent 0bdbf94 commit 5c7b11e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ Converting (scoped)enum values to/from string names written in C++>=11.
* Supports `enum` and `enum class`
* Supports enums in namespaces, classes or structs even templated or not
* Supports compile-time as much as possible using with C++14 and later
* Changing enum range with template parameter <sub>(default range: `[-128, 128)`)</sub> on each call or with your special function for types or adding specialized enum_range<Enum> struct
* Changing enum range with template parameter <sub>(default range: `[-128, 128)`)</sub> on each call or with your special function for types or adding specialized `enum_range<Enum>` struct
* Supports `operator<<` for direct using with ostream objects
* Supports basic `flat_map` when using to_enum with range >= 10 instead of linear search
* Supports custom enum name output by explicit specialization of `constexpr inline auto mgutility::detail::enum_type::name<Enum, EnumValue>() noexcept` function

## Limitations
* Compiler versions
* Wider range can increase compile time so user responsible to adjusting for enum's range


## Usage ([try it!](https://godbolt.org/z/cKsEo353T))
## Usage ([try it!](https://godbolt.org/z/8Ye1PhKhs))
```C++
#include <iostream>
#include "enum_name.hpp"
Expand All @@ -29,6 +29,12 @@ enum class rgb_color { red, green, blue, unknown = -1};

// you can specialize enum ranges with specialize struct per enum types (option 1)
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"; }
}

template<>
struct enum_range<rgb_color>
{
Expand Down

0 comments on commit 5c7b11e

Please sign in to comment.