update doc

This commit is contained in:
Neargye 2020-01-25 23:45:33 +05:00
parent 04578f3316
commit f9078cc9f9
3 changed files with 105 additions and 62 deletions

View file

@ -42,6 +42,7 @@ Header-only C++17 library provides nameof macros and functions to simply obtain
## [Examples](example/example.cpp) ## [Examples](example/example.cpp)
* Nameof * Nameof
```cpp ```cpp
// Name of variable. // Name of variable.
NAMEOF(somevar) -> "somevar" NAMEOF(somevar) -> "somevar"
@ -62,6 +63,7 @@ Header-only C++17 library provides nameof macros and functions to simply obtain
``` ```
* Nameof enum * Nameof enum
```cpp ```cpp
auto color = Color::RED; auto color = Color::RED;
// Name of enum variable. // Name of enum variable.
@ -75,6 +77,7 @@ Header-only C++17 library provides nameof macros and functions to simply obtain
``` ```
* Nameof type * Nameof type
```cpp ```cpp
using T = const int&; using T = const int&;
T var = 42; T var = 42;
@ -92,6 +95,7 @@ Header-only C++17 library provides nameof macros and functions to simply obtain
``` ```
* Compile-time * Compile-time
```cpp ```cpp
constexpr auto somevar_name = NAMEOF(somevar); constexpr auto somevar_name = NAMEOF(somevar);
// somevar_name -> "somevar" // somevar_name -> "somevar"
@ -103,6 +107,10 @@ Header-only C++17 library provides nameof macros and functions to simply obtain
// type_name -> "int" // type_name -> "int"
``` ```
## Remarks
* Before use, read the [limitations](doc/limitations.md) of functionality.
## Integration ## Integration
You should add required file [nameof.hpp](include/nameof.hpp). You should add required file [nameof.hpp](include/nameof.hpp).

View file

@ -1,8 +1,10 @@
# Nameof # Limitations
## Nameof
* If argument does not have name, occurs the compilation error `"Expression does not have a name."`. * If argument does not have name, occurs the compilation error `"Expression does not have a name."`.
# Nameof Type ## Nameof Type
* To check is nameof type supported compiler use macro `NAMEOF_TYPE_SUPPORTED` or constexpr constant `nameof::is_nameof_type_supported`. * To check is nameof type supported compiler use macro `NAMEOF_TYPE_SUPPORTED` or constexpr constant `nameof::is_nameof_type_supported`.
@ -12,7 +14,7 @@
* If argument does not have name, occurs the compilation error `"Expression does not have a name."`. * If argument does not have name, occurs the compilation error `"Expression does not have a name."`.
# Nameof Enum ## Nameof Enum
* To check is nameof enum supported compiler use macro `NAMEOF_ENUM_SUPPORTED` or constexpr constant `nameof::is_nameof_enum_supported`. * To check is nameof enum supported compiler use macro `NAMEOF_ENUM_SUPPORTED` or constexpr constant `nameof::is_nameof_enum_supported`.
@ -20,16 +22,24 @@
* Enum can't reflect if the enum is a forward declaration. * Enum can't reflect if the enum is a forward declaration.
* Enum value must be in range `[NAMEOF_ENUM_RANGE_MIN, NAMEOF_ENUM_RANGE_MAX]`. By default `NAMEOF_ENUM_RANGE_MIN = -128`, `NAMEOF_ENUM_RANGE_MAX = 128`. * Enum value must be in range `[NAMEOF_ENUM_RANGE_MIN, NAMEOF_ENUM_RANGE_MAX]`.
* By default `NAMEOF_ENUM_RANGE_MIN = -128`, `NAMEOF_ENUM_RANGE_MAX = 128`.
* `NAMEOF_ENUM_RANGE_MIN` must be less or equals than `0` and must be greater than `INT16_MIN`.
* `NAMEOF_ENUM_RANGE_MAX` must be greater than `0` and must be less than `INT16_MAX`.
* If need another range for all enum types by default, redefine the macro `NAMEOF_ENUM_RANGE_MIN` and `NAMEOF_ENUM_RANGE_MAX`.
* If need another range for all enum types by default, redefine the macro `NAMEOF_ENUM_RANGE_MIN` and `NAMEOF_ENUM_RANGE_MAX`.
```cpp ```cpp
#define NAMEOF_ENUM_RANGE_MIN 0 #define NAMEOF_ENUM_RANGE_MIN 0
#define NAMEOF_ENUM_RANGE_MAX 256 #define NAMEOF_ENUM_RANGE_MAX 256
#include <nameof.hpp> #include <nameof.hpp>
``` ```
* If need another range for specific enum type, add specialization `enum_range` for necessary enum type. * If need another range for specific enum type, add specialization `enum_range` for necessary enum type.
```cpp ```cpp
#include <nameof.hpp> #include <nameof.hpp>
@ -44,7 +54,20 @@
} }
``` ```
* If you hit a message like this:
```text
[...]
note: constexpr evaluation hit maximum step limit; possible infinite loop?
```
Change the limit for the number of constexpr evaluated:
* MSVC `/constexpr:depthN`, `/constexpr:stepsN` <https://docs.microsoft.com/en-us/cpp/build/reference/constexpr-control-constexpr-evaluation>
* Clang `-fconstexpr-depth=N`, `-fconstexpr-steps=N` <https://clang.llvm.org/docs/UsersManual.html#controlling-implementation-limits>
* GCC `-fconstexpr-depth=N`, `-fconstexpr-loop-limit=N`, `-fconstexpr-ops-limit=N` <https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/C_002b_002b-Dialect-Options.html>
* Nameof enum obtains the first defined value enums, and won't work if value are aliased. * Nameof enum obtains the first defined value enums, and won't work if value are aliased.
```cpp ```cpp
enum ShapeKind { enum ShapeKind {
ConvexBegin = 0, ConvexBegin = 0,
@ -58,7 +81,9 @@
// nameof::nameof_enum(ShapeKind::Box) -> "ConvexBegin" // nameof::nameof_enum(ShapeKind::Box) -> "ConvexBegin"
// NAMEOF_ENUM(ShapeKind::Box) -> "ConvexBegin" // NAMEOF_ENUM(ShapeKind::Box) -> "ConvexBegin"
``` ```
Work around the issue: Work around the issue:
```cpp ```cpp
enum ShapeKind { enum ShapeKind {
// Convex shapes, see ConvexBegin and ConvexEnd below. // Convex shapes, see ConvexBegin and ConvexEnd below.

View file

@ -1,30 +1,29 @@
# Reference # Reference
* [`NAMEOF` macro that obtains simple (unqualified) string name of variable, function, macro.](#NAMEOF) * [`NAMEOF` macro that obtains simple (unqualified) string name of variable, function, macro.](#nameof)
* [`NAMEOF_FULL` macro that obtains simple (unqualified) full (with template suffix) string name of variable, function, macro.](#NAMEOF_FULL) * [`NAMEOF_FULL` macro that obtains simple (unqualified) full (with template suffix) string name of variable, function, macro.](#nameof_full)
* [`NAMEOF_RAW` macro that obtains raw string name of variable, function, macro.](#NAMEOF_RAW) * [`NAMEOF_RAW` macro that obtains raw string name of variable, function, macro.](#nameof_raw)
* [`nameof_enum(E value)` function that obtains simple (unqualified) string enum name of enum variable.](#nameof_enum(value)) * [`nameof_enum` function that obtains simple (unqualified) string enum name of enum variable.](#nameof_enum)
* [`nameof_enum<auto V>()` function that obtains simple (unqualified) string enum name of static storage enum variable.](#nameof_enum<Value>()) * [`NAMEOF_ENUM` macro that obtains simple (unqualified) string enum name of enum variable.](#nameof_enum-1)
* [`NAMEOF_ENUM` macro that obtains simple (unqualified) string enum name of enum variable.](#NAMEOF_ENUM)
* [`NAMEOF_CONST_ENUM` macro that obtains simple (unqualified) string enum name of static storage enum variable.](#NAMEOF_CONST_ENUM) * [`NAMEOF_CONST_ENUM` macro that obtains simple (unqualified) string enum name of static storage enum variable.](#NAMEOF_CONST_ENUM)
* [`nameof_type<T>()` function that obtains string name of type, reference and cv-qualifiers are ignored.](#nameof_type<T>()) * [`nameof_type` function that obtains string name of type, reference and cv-qualifiers are ignored.](#nameof_type)
* [`nameof_full_type<T>()` function that obtains string name of full type, with reference and cv-qualifiers.](#nameof_full_type<T>()) * [`nameof_full_type` function that obtains string name of full type, with reference and cv-qualifiers.](#nameof_full_type)
* [`NAMEOF_TYPE` macro that obtains string name of type, reference and cv-qualifiers are ignored.](#NAMEOF_TYPE) * [`NAMEOF_TYPE` macro that obtains string name of type, reference and cv-qualifiers are ignored.](#nameof_type-1)
* [`NAMEOF_FULL_TYPE` macro that obtains string name of full type, with reference and cv-qualifiers.](#NAMEOF_FULL_TYPE) * [`NAMEOF_FULL_TYPE` macro that obtains string name of full type, with reference and cv-qualifiers.](#nameof_full_type-1)
* [`NAMEOF_TYPE_EXPR` macro that obtains string name type of expression, reference and cv-qualifiers are ignored.](#NAMEOF_TYPE_EXPR) * [`NAMEOF_TYPE_EXPR` macro that obtains string name type of expression, reference and cv-qualifiers are ignored.](#nameof_type_expr)
* [`NAMEOF_FULL_TYPE_EXPR` macro that obtains string name full type of expression, with reference and cv-qualifiers.](#NAMEOF_FULL_TYPE_EXPR) * [`NAMEOF_FULL_TYPE_EXPR` macro that obtains string name full type of expression, with reference and cv-qualifiers.](#nameof_full_type_expr)
# Synopsis ## Synopsis
* Before use, read the [limitations](limitations.md) of functionality. * Before use, read the [limitations](limitations.md) of functionality.
* All functions `constexpr` and `noexcept`. * All functions `constexpr` and `noexcept`.
* To check is nameof_type supported compiler use macro `NAMEOF_TYPE_SUPPORTED` or constexpr constant `nameof::is_nameof_type_supported`. * To check is nameof_type supported compiler use macro `NAMEOF_TYPE_SUPPORTED` or constexpr constant `nameof::is_nameof_type_supported`.</br>
If nameof_type used on unsupported compiler, occurs the compilation error. To suppress error define macro `NAMEOF_TYPE_NO_CHECK_SUPPORT`. If nameof_type used on unsupported compiler, occurs the compilation error. To suppress error define macro `NAMEOF_TYPE_NO_CHECK_SUPPORT`.
* To check is nameof_enum supported compiler use macro `NAMEOF_ENUM_SUPPORTED` or constexpr constant `nameof::is_nameof_enum_supported`. * To check is nameof_enum supported compiler use macro `NAMEOF_ENUM_SUPPORTED` or constexpr constant `nameof::is_nameof_enum_supported`.</br>
If nameof_enum used on unsupported compiler, occurs the compilation error. To suppress error define macro `NAMEOF_ENUM_NO_CHECK_SUPPORT`. If nameof_enum used on unsupported compiler, occurs the compilation error. To suppress error define macro `NAMEOF_ENUM_NO_CHECK_SUPPORT`.
## `NAMEOF` ## `NAMEOF`
@ -35,6 +34,7 @@ If nameof_enum used on unsupported compiler, occurs the compilation error. To su
* If argument does not have name, occurs the compilation error `"Expression does not have a name."`. * If argument does not have name, occurs the compilation error `"Expression does not have a name."`.
* Examples * Examples
```cpp ```cpp
// Name of variable. // Name of variable.
NAMEOF(somevar) -> "somevar" NAMEOF(somevar) -> "somevar"
@ -63,6 +63,7 @@ If nameof_enum used on unsupported compiler, occurs the compilation error. To su
* If argument does not have name, occurs the compilation error `"Expression does not have a name."`. * If argument does not have name, occurs the compilation error `"Expression does not have a name."`.
* Examples * Examples
```cpp ```cpp
// Full name of template function. // Full name of template function.
NAMEOF_FULL(foo<int, float>()) -> "foo<int, float>" NAMEOF_FULL(foo<int, float>()) -> "foo<int, float>"
@ -80,36 +81,37 @@ If nameof_enum used on unsupported compiler, occurs the compilation error. To su
* If argument does not have name, occurs the compilation error `"Expression does not have a name."`. * If argument does not have name, occurs the compilation error `"Expression does not have a name."`.
* Examples * Examples
```cpp ```cpp
NAMEOF_RAW(::somevar.somefield) -> "::somevar.somefield" NAMEOF_RAW(::somevar.somefield) -> "::somevar.somefield"
NAMEOF_RAW(&some_class::some_method<int>) -> "&some_class::some_method<int>" NAMEOF_RAW(&some_class::some_method<int>) -> "&some_class::some_method<int>"
``` ```
## `nameof_enum(value)` ## `nameof_enum`
* Function that obtains simple (unqualified) string enum name of enum variable. * Function that obtains simple (unqualified) string enum name of enum variable.
* Returns `std::string_view`. * Returns `std::string_view`.
* If argument does not have name, returns empty `std::string_view`. * Enum variable to string.
* If argument does not have name or [out of range](limitations.md#nameof-enum), returns empty `std::string_view`.
* Examples
* Examples
```cpp ```cpp
auto color = Color::RED; auto color = Color::RED;
nameof::nameof_enum(color) -> "RED" nameof::nameof_enum(color) -> "RED"
``` ```
## `nameof_enum<Value>()` * Static storage enum variable to string.
* Function that obtains simple (unqualified) string enum name of static storage enum variable. * This version is much lighter on the compile times and is not restricted to the enum_range [limitation](limitations.md#nameof-enum).
* Returns `std::string_view`. * If argument does not have name, occurs the compilation error `"Enum value does not have a name."`.
* This version is much lighter on the compile times and is not restricted to the enum_range [limitation](limitations.md). * Examples
* If argument does not have name, returns empty `std::string_view`.
* Examples
```cpp ```cpp
nameof::nameof_enum<Color::GREEN>() -> "GREEN" nameof::nameof_enum<Color::GREEN>() -> "GREEN"
``` ```
@ -120,9 +122,10 @@ If nameof_enum used on unsupported compiler, occurs the compilation error. To su
* Returns `std::string_view`. * Returns `std::string_view`.
* If argument does not have name, returns empty `std::string_view`. * If argument does not have name or [out of range](limitations.md#nameof-enum), returns empty `std::string_view`.
* Examples * Examples
```cpp ```cpp
auto color = Color::RED; auto color = Color::RED;
NAMEOF_ENUM(color) -> "RED" NAMEOF_ENUM(color) -> "RED"
@ -134,16 +137,17 @@ If nameof_enum used on unsupported compiler, occurs the compilation error. To su
* Returns `std::string_view`. * Returns `std::string_view`.
* This version is much lighter on the compile times and is not restricted to the enum_range [limitation](limitations.md). * This version is much lighter on the compile times and is not restricted to the enum_range [limitation](limitations.md#nameof-enum).
* If argument does not have name, returns empty `std::string_view`. * If argument does not have name, occurs the compilation error `"Enum value does not have a name."`.
* Examples * Examples
```cpp ```cpp
NAMEOF_CONST_ENUM(Color::GREEN) -> "GREEN" NAMEOF_CONST_ENUM(Color::GREEN) -> "GREEN"
``` ```
## `nameof_type<T>()` ## `nameof_type`
* Function macro that obtains string name of type, reference and cv-qualifiers are ignored. * Function macro that obtains string name of type, reference and cv-qualifiers are ignored.
@ -156,12 +160,13 @@ If nameof_enum used on unsupported compiler, occurs the compilation error. To su
* If argument does not have name, occurs the compilation error `"Expression does not have a name."`. * If argument does not have name, occurs the compilation error `"Expression does not have a name."`.
* Examples * Examples
```cpp ```cpp
using T = const int&; using T = const int&;
nameof::nameof_type<T>() -> "int" nameof::nameof_type<T>() -> "int"
``` ```
## `nameof_full_type<T>()` ## `nameof_full_type`
* Function that obtains string name of full type, with reference and cv-qualifiers. * Function that obtains string name of full type, with reference and cv-qualifiers.
@ -172,6 +177,7 @@ If nameof_enum used on unsupported compiler, occurs the compilation error. To su
* If argument does not have name, occurs the compilation error `"Expression does not have a name."`. * If argument does not have name, occurs the compilation error `"Expression does not have a name."`.
* Examples * Examples
```cpp ```cpp
using T = const int&; using T = const int&;
nameof::nameof_full_type<T>() -> "const int&" nameof::nameof_full_type<T>() -> "const int&"
@ -190,6 +196,7 @@ If nameof_enum used on unsupported compiler, occurs the compilation error. To su
* If argument does not have name, occurs the compilation error `"Expression does not have a name."`. * If argument does not have name, occurs the compilation error `"Expression does not have a name."`.
* Examples * Examples
```cpp ```cpp
using T = const int&; using T = const int&;
NAMEOF_TYPE(T) -> "int" NAMEOF_TYPE(T) -> "int"
@ -206,6 +213,7 @@ If nameof_enum used on unsupported compiler, occurs the compilation error. To su
* If argument does not have name, occurs the compilation error `"Expression does not have a name."`. * If argument does not have name, occurs the compilation error `"Expression does not have a name."`.
* Examples * Examples
```cpp ```cpp
using T = const int&; using T = const int&;
NAMEOF_TYPE(T) -> "const int&" NAMEOF_TYPE(T) -> "const int&"
@ -224,13 +232,14 @@ If nameof_enum used on unsupported compiler, occurs the compilation error. To su
* If argument does not have name, occurs the compilation error `"Expression does not have a name."`. * If argument does not have name, occurs the compilation error `"Expression does not have a name."`.
* Examples * Examples
```cpp ```cpp
using T = const int&; using T = const int&;
T var = 42; T var = 42;
NAMEOF_TYPE_EXPR(var) -> "int" NAMEOF_TYPE_EXPR(var) -> "int"
``` ```
## `NAMEOF_TYPE_EXPR` ## `NAMEOF_FULL_TYPE_EXPR`
* Macro that obtains string name full type of expression, with reference and cv-qualifiers. * Macro that obtains string name full type of expression, with reference and cv-qualifiers.
@ -241,6 +250,7 @@ If nameof_enum used on unsupported compiler, occurs the compilation error. To su
* If argument does not have name, occurs the compilation error `"Expression does not have a name."`. * If argument does not have name, occurs the compilation error `"Expression does not have a name."`.
* Examples * Examples
```cpp ```cpp
using T = const int&; using T = const int&;
T var = 42; T var = 42;