From 06741ec03f6827ca4bc80f3260bf3e2ed08d0f38 Mon Sep 17 00:00:00 2001 From: neargye Date: Wed, 20 Nov 2024 00:07:21 +0200 Subject: [PATCH] update doc --- README.md | 17 ++++++++++++++-- doc/reference.md | 50 +++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 60 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 678f8d3..f11fc6f 100644 --- a/README.md +++ b/README.md @@ -22,11 +22,24 @@ If you like this project, please consider donating to one of the funds that help ## [Features & Examples](example/) -* Enum value to string +* Basic ```cpp #include - //.... + #include + + enum class Color : { RED = -10, BLUE = 0, GREEN = 10 }; + + int main() { + Color c1 = Color::RED; + std::cout << magic_enum::enum_name(c1) << std::endl; // RED + return 0; + } + ``` + +* Enum value to string + + ```cpp Color color = Color::RED; auto color_name = magic_enum::enum_name(color); // color_name -> "RED" diff --git a/doc/reference.md b/doc/reference.md index a81bb3b..6eb4a3c 100644 --- a/doc/reference.md +++ b/doc/reference.md @@ -76,6 +76,8 @@ template constexpr optional enum_cast(string_view value, BinaryPredicate p) noexcept(is_nothrow_invocable_v); ``` +* Defined in header `` + * Obtains enum value from string or integer. * Returns `optional`, using `has_value()` to check contains enum value and `value()` to get the enum value. @@ -125,6 +127,8 @@ template constexpr E enum_value() noexcept; ``` +* Defined in header `` + * Returns enum value at specified index. * `enum_value(value)` no bounds checking is performed: the behavior is undefined if `index >= number of enum values`. * `enum_value()` check if `I >= number of enum values`, occurs the compilation error `magic_enum::enum_value out of range`. @@ -149,6 +153,8 @@ template constexpr array enum_values() noexcept; ``` +* Defined in header `` + * Returns `array` with all enum values where `N = number of enum values`, sorted by enum value. * Examples @@ -166,6 +172,8 @@ template constexpr size_t enum_count() noexcept; ``` +* Defined in header `` + * Returns number of enum values. * Examples @@ -185,6 +193,8 @@ template constexpr underlying_type_t enum_underlying(E value) noexcept; ``` +* Defined in header `` + * Returns integer value from enum value. * Examples @@ -205,6 +215,8 @@ template constexpr string_view enum_name() noexcept; ``` +* Defined in header `` + * Returns name from enum value as `string_view` with null-terminated string. * If enum value does not have name or [out of range](limitations.md), `enum_name(value)` returns empty string. * If enum value does not have name, `enum_name()` occurs the compilation error `magic_enum::enum_name enum value does not have a name`. @@ -232,6 +244,8 @@ template constexpr array enum_names() noexcept; ``` +* Defined in header `` + * Returns `array` with all names where `N = number of enum values`, sorted by enum value. * Examples @@ -249,6 +263,8 @@ template constexpr array, N> enum_entries() noexcept; ``` +* Defined in header `` + * Returns `array, N>` with all pairs (value, name) where `N = number of enum values`, sorted by enum value. * Examples @@ -270,6 +286,8 @@ template constexpr size_t enum_index() noexcept; ``` +* Defined in header `` + * Obtains index in enum values from enum value. * `enum_index(value)` returns `optional` with index. * `enum_index()` returns index. If enum value does not have a index, occurs the compilation error `magic_enum::enum_index enum value does not have a index`. @@ -303,6 +321,8 @@ template constexpr bool enum_contains(string_view value, BinaryPredicate p) noexcept(is_nothrow_invocable_v); ``` +* Defined in header `` + * Checks whether enum contains enumerator with such value. * Returns true is enum contains value, otherwise false. @@ -327,6 +347,8 @@ template constexpr bool enum_reflected(underlying_type_t value) noexcept; ``` +* Defined in header `` + * Returns true if the enum value is in the range of values that can be reflected. ## `enum_type_name` @@ -336,6 +358,8 @@ template constexpr string_view enum_type_name() noexcept; ``` +* Defined in header `` + * Returns type name of enum as `string_view` null-terminated string. * Examples @@ -353,7 +377,7 @@ template constexpr optional enum_fuse(Es... values) noexcept; ``` -* You should add the required file ``. +* Defined in header `` * Returns a typesafe bijective mix of several enum values. This can be used to emulate 2D switch/case statements. @@ -384,7 +408,7 @@ template constexpr Result enum_switch(Lambda&& lambda, E value, Result&& result); ``` -* You should add the required file ``. +* Defined in header `` * Examples @@ -404,6 +428,8 @@ template constexpr auto enum_for_each(Lambda&& lambda); ``` +* Defined in header `` + * Examples ```cpp @@ -442,7 +468,7 @@ template constexpr bool enum_flags_contains(string_view value, BinaryPredicate p) noexcept(is_nothrow_invocable_v); ``` -* You should add the required file ``. +* Defined in header `` * For enum-flags add `is_flags` to specialization `enum_range` for necessary enum type. Specialization of `enum_range` must be injected in `namespace magic_enum::customize`. ```cpp @@ -496,6 +522,8 @@ template inline constexpr bool is_unscoped_enum_v = is_unscoped_enum::value; ``` +* Defined in header `` + * Checks whether type is an [Unscoped enumeration](https://en.cppreference.com/w/cpp/language/enum#Unscoped_enumeration). * Provides the member constant value which is equal to true, if T is an [Unscoped enumeration](https://en.cppreference.com/w/cpp/language/enum#Unscoped_enumeration) type.
@@ -521,6 +549,8 @@ template inline constexpr bool is_scoped_enum_v = is_scoped_enum::value; ``` +* Defined in header `` + * Checks whether type is an [Scoped enumeration](https://en.cppreference.com/w/cpp/language/enum#Scoped_enumerations). * Provides the member constant value which is equal to true, if T is an [Scoped enumeration](https://en.cppreference.com/w/cpp/language/enum#Scoped_enumerations) type.
@@ -546,6 +576,8 @@ template using underlying_type_t = typename underlying_type::type; ``` +* Defined in header `` + * Improved UB-free "SFINAE-friendly" [underlying_type](https://en.cppreference.com/w/cpp/types/underlying_type). * If T is a complete enumeration type, provides a member typedef type that names the underlying type of T.
@@ -571,7 +603,7 @@ template basic_ostream& operator<<(basic_ostream& os, optional value); ``` -* You should add the required file ``. +* Defined in header `` * Out-of-the-box ostream operators for all enums. @@ -590,7 +622,7 @@ template basic_istream& operator>>(basic_istream& is, E& value); ``` -* You should add the required file ``. +* Defined in header `` * Out-of-the-box istream operators for all enums. @@ -627,6 +659,8 @@ template constexpr E& operator^=(E& lhs, E rhs) noexcept; ``` +* Defined in header `` + * Out-of-the-box bitwise operators for all enums. * Examples @@ -712,6 +746,8 @@ struct array { } ``` +* Defined in header `` + * STL like array for all enums. * Examples @@ -824,6 +860,8 @@ class bitset { } ``` +* Defined in header `` + * STL like bitset for all enums. * Examples @@ -975,6 +1013,8 @@ class set { } ``` +* Defined in header `` + * STL like set for all enums. * Examples