little readme fixes

This commit is contained in:
BlackMATov
2020-12-19 00:27:24 +07:00
parent fce42579f0
commit 70ae153ee8

View File

@@ -48,15 +48,22 @@ target_link_libraries(your_project_target enum.hpp)
## Examples ## Examples
### Declarations - [Enum declarations](#Enum-declarations)
- [Traits using](#Traits-using)
- [Generic context](#Generic-context)
- [Adapting external enums](#Adapting-external-enums)
### Enum declarations
```cpp ```cpp
// declaration of unscoped enumeration `debug_level` with traits
ENUM_HPP_DECL(debug_level, int, ENUM_HPP_DECL(debug_level, int,
(level_info) (level_info)
(level_warning) (level_warning)
(level_error)) (level_error))
// equivalent to: /* equivalent to:
enum debug_level : int { enum debug_level : int {
level_info, level_info,
@@ -65,18 +72,20 @@ enum debug_level : int {
}; };
struct debug_level_traits { struct debug_level_traits {
/*...*/ ...
}; };*/
``` ```
```cpp ```cpp
// declaration of scoped enumeration `color` with traits
ENUM_HPP_CLASS_DECL(color, unsigned, ENUM_HPP_CLASS_DECL(color, unsigned,
(red = 1 << 0) (red = 1 << 0)
(green = 1 << 1) (green = 1 << 1)
(blue = 1 << 2) (blue = 1 << 2)
(white = red | green | blue)) (white = red | green | blue))
// equivalent to: /* equivalent to:
enum class color : unsigned { enum class color : unsigned {
red = 1 << 0, red = 1 << 0,
@@ -86,8 +95,8 @@ enum class color : unsigned {
}; };
struct color_traits { struct color_traits {
/*...*/ ...
}; };*/
``` ```
### Traits using ### Traits using
@@ -126,7 +135,7 @@ int main() {
static_assert(color_traits::from_index(42) == std::nullopt); static_assert(color_traits::from_index(42) == std::nullopt);
// names // names
for ( auto n : color_traits::names ) { for ( std::string_view n : color_traits::names ) {
std::cout << n << ","; std::cout << n << ",";
} // stdout: red,green,blue, } // stdout: red,green,blue,
@@ -192,22 +201,25 @@ int main() {
## API ## API
- [Enum traits](#Enum-traits)
- [Generic functions](#Generic-functions)
### Enum traits ### Enum traits
```cpp ```cpp
// declare enum // declare unscoped enumeration
ENUM_HPP_DECL( ENUM_HPP_DECL(
/*enum_name*/, /*enum_name*/,
/*underlying_type*/, /*underlying_type*/,
/*fields*/) /*fields*/)
// declare enum class // declare scoped enumeration
ENUM_HPP_CLASS_DECL( ENUM_HPP_CLASS_DECL(
/*enum_name*/, /*enum_name*/,
/*underlying_type*/, /*underlying_type*/,
/*fields*/) /*fields*/)
// declare only traits // declare only traits for external enumerations
ENUM_HPP_TRAITS_DECL( ENUM_HPP_TRAITS_DECL(
/*enum_name*/, /*enum_name*/,
/*fields*/) /*fields*/)