update doc

This commit is contained in:
neargye 2023-03-30 19:10:22 +04:00
parent 1f071407dc
commit 6708611448
9 changed files with 157 additions and 19 deletions

View file

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2016 - 2022 Daniil Goncharov
Copyright (c) 2016 - 2023 Daniil Goncharov
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View file

@ -28,6 +28,7 @@ Header-only C++17 library provides nameof macros and functions to simply obtain
* Compile-time
* Name of variable, member variable
* Name of type, variable type
* Name of member, pointer
* Name of function, member function
* Name of enum, enum variable
* Name of macro
@ -149,9 +150,6 @@ CPMAddPackage(
## Compiler compatibility
* Clang/LLVM >= 6
* MSVC++ >= 14.11 / Visual Studio >= 2017
* Xcode >= 10
* GCC >= 7 (GCC >= 9 for NAMEOF_ENUM)
Check in the [reference](doc/reference.md) for each features.
## Licensed under the [MIT License](LICENSE)

View file

@ -16,6 +16,12 @@
* To check if nameof_type_rtti is supported by your compiler use macro `NAMEOF_TYPE_RTTI_SUPPORTED` or constexpr constant `nameof::is_nameof_type_rtti_supported`.</br>
If nameof_type_rtti is used on an unsupported compiler, a compilation error occurs. To suppress the error define the macro `NAMEOF_TYPE_NO_CHECK_SUPPORT`.
* To check is nameof_member supported compiler use macro `NAMEOF_MEMBER_SUPPORTED` or constexpr constant `nameof::is_nameof_member_supported`.</br>
If nameof_member used on unsupported compiler, occurs the compilation error. To suppress error define macro `NAMEOF_TYPE_NO_CHECK_SUPPORT`.
* To check is nameof_pointer supported compiler use macro `NAMEOF_POINTER_SUPPORTED` or constexpr constant `nameof::is_nameof_pointer_supported`.</br>
If nameof_pointer used on unsupported compiler, occurs the compilation error. To suppress error define macro `NAMEOF_TYPE_NO_CHECK_SUPPORT`.
## Nameof Enum
* This library uses a compiler-specific hack (based on `__PRETTY_FUNCTION__` / `__FUNCSIG__`), which works on Clang >= 5, MSVC >= 15.3 and GCC >= 9.

View file

@ -16,19 +16,27 @@
* [`NAMEOF_TYPE_RTTI` obtains type name, using RTTI.](#nameof_type_rtti)
* [`NAMEOF_FULL_TYPE_RTTI` obtains short type name, using RTTI.](#nameof_full_type_rtti)
* [`NAMEOF_SHORT_TYPE_RTTI` obtains short type name, using RTTI.](#nameof_short_type_rtti)
* [`NAMEOF_MEMBER` obtains name of member.](#nameof_member)
* [`NAMEOF_POINTER` obtains name of a function, a global or class static variable.](#nameof_pointer)
## Synopsis
* Before use, read the [limitations](limitations.md) of functionality.
* 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`.
* 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`.
* To check is nameof_type_rtti supported compiler use macro `NAMEOF_TYPE_RTTI_SUPPORTED` or constexpr constant `nameof::is_nameof_type_rtti_supported`.</br>
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`.</br>
If nameof_enum used on unsupported compiler, occurs the compilation error. To suppress error define macro `NAMEOF_ENUM_NO_CHECK_SUPPORT`.
* To check is nameof_member supported compiler use macro `NAMEOF_MEMBER_SUPPORTED` or constexpr constant `nameof::is_nameof_member_supported`.</br>
If nameof_member used on unsupported compiler, occurs the compilation error. To suppress error define macro `NAMEOF_TYPE_NO_CHECK_SUPPORT`.
* To check is nameof_pointer supported compiler use macro `NAMEOF_POINTER_SUPPORTED` or constexpr constant `nameof::is_nameof_pointer_supported`.</br>
If nameof_pointer used on unsupported compiler, occurs the compilation error. To suppress error define macro `NAMEOF_TYPE_NO_CHECK_SUPPORT`.
* To add custom enum or type names see the [example](../example/example_custom_name.cpp).
@ -71,6 +79,11 @@
NAMEOF(NAMEOF(structvar)) -> "NAMEOF"
```
* Compiler compatibility
Clang/LLVM >= 5 and C++ >= 17</br>
Visual Studio >= 2017 and C++ >= 17</br>
GCC >= 7 and C++ >= 17</br>
## `NAMEOF_FULL`
* Obtains full (with template suffix) name of variable, function, macro.
@ -89,6 +102,11 @@
NAMEOF_FULL(somevar.some_method<int>()) -> "some_method<int>"
```
* Compiler compatibility
Clang/LLVM >= 5 and C++ >= 17</br>
Visual Studio >= 2017 and C++ >= 17</br>
GCC >= 7 and C++ >= 17</br>
## `NAMEOF_RAW`
* Obtains raw name of variable, function, macro.
@ -104,6 +122,10 @@
NAMEOF_RAW(&some_class::some_method<int>) -> "&some_class::some_method<int>"
```
* Compiler compatibility
Clang/LLVM >= 5 and C++ >= 17</br>
Visual Studio >= 2017 and C++ >= 17</br>
GCC >= 7 and C++ >= 17</br>
## `NAMEOF_ENUM`
@ -121,6 +143,11 @@
nameof::nameof_enum(color) -> "RED"
```
* Compiler compatibility
Clang/LLVM >= 5 and C++ >= 17</br>
Visual Studio >= 2017 and C++ >= 17</br>
GCC >= 9 and C++ >= 17</br>
# `NAMEOF_ENUM_OR`
* Obtains name of enum variable or default value if enum variable out of range.
@ -129,6 +156,19 @@
* If argument does not have name or [out of range](limitations.md#nameof-enum), returns `default_value`.
```cpp
auto color = Color::RED;
NAMEOF_ENUM_OR(color, "none") -> "RED"
NAMEOF_ENUM_OR((Color)-1, "none") -> "none"
nameof::nameof_enum_or(color, "none") -> "RED"
nameof::nameof_enum_or((Color)-1, "none") -> "none"
```
* Compiler compatibility
Clang/LLVM >= 5 and C++ >= 17</br>
Visual Studio >= 2017 and C++ >= 17</br>
GCC >= 9 and C++ >= 17</br>
## `NAMEOF_ENUM_CONST`
* Obtains name of static storage enum variable.
@ -146,6 +186,11 @@
nameof::nameof_enum<Color::GREEN>() -> "GREEN"
```
* Compiler compatibility
Clang/LLVM >= 5 and C++ >= 17</br>
Visual Studio >= 2017 and C++ >= 17</br>
GCC >= 9 and C++ >= 17</br>
## `NAMEOF_ENUM_FLAG`
* Obtains name of enum flag variable.
@ -171,6 +216,11 @@
nameof_enum(HasClaws | CanFly) -> ""
```
* Compiler compatibility
Clang/LLVM >= 5 and C++ >= 17</br>
Visual Studio >= 2017 and C++ >= 17</br>
GCC >= 9 and C++ >= 17</br>
## `NAMEOF_TYPE`
* Obtains type name, reference and cv-qualifiers are ignored.
@ -192,6 +242,11 @@
nameof::nameof_type<T>() -> "int"
```
* Compiler compatibility
Clang/LLVM >= 5 and C++ >= 17</br>
Visual Studio >= 2017 and C++ >= 17</br>
GCC >= 7 and C++ >= 17</br>
## `NAMEOF_FULL_TYPE`
* Obtains full type name, with reference and cv-qualifiers.
@ -210,6 +265,11 @@
nameof::nameof_full_type<T>() -> "const int&"
```
* Compiler compatibility
Clang/LLVM >= 5 and C++ >= 17</br>
Visual Studio >= 2017 and C++ >= 17</br>
GCC >= 7 and C++ >= 17</br>
## `NAMEOF_SHORT_TYPE`
* Obtains short type name.
@ -228,6 +288,11 @@
nameof::nameof_short_type<T>() -> "SomeClass"
```
* Compiler compatibility
Clang/LLVM >= 5 and C++ >= 17</br>
Visual Studio >= 2017 and C++ >= 17</br>
GCC >= 7 and C++ >= 17</br>
## `NAMEOF_TYPE_EXPR`
* Obtains string name type of expression, reference and cv-qualifiers are ignored.
@ -249,6 +314,11 @@
nameof::nameof_type<decltype(var)>() -> "int"
```
* Compiler compatibility
Clang/LLVM >= 5 and C++ >= 17</br>
Visual Studio >= 2017 and C++ >= 17</br>
GCC >= 7 and C++ >= 17</br>
## `NAMEOF_FULL_TYPE_EXPR`
* Obtains full type name of expression, with reference and cv-qualifiers.
@ -268,6 +338,11 @@
nameof::nameof_full_type<decltype(var)>() -> "const int&"
```
* Compiler compatibility
Clang/LLVM >= 5 and C++ >= 17</br>
Visual Studio >= 2017 and C++ >= 17</br>
GCC >= 7 and C++ >= 17</br>
## `NAMEOF_SHORT_TYPE_EXPR`
* Obtains short type name of expression.
@ -286,6 +361,11 @@
nameof::nameof_short_type<decltype(var)>() -> "SomeClass"
```
* Compiler compatibility
Clang/LLVM >= 5 and C++ >= 17</br>
Visual Studio >= 2017 and C++ >= 17</br>
GCC >= 7 and C++ >= 17</br>
## `NAMEOF_TYPE_RTTI`
* Obtains type name, using RTTI.
@ -299,6 +379,11 @@
NAMEOF_TYPE_RTTI(*ptr) -> "my::detail::Derived"
```
* Compiler compatibility
Clang/LLVM >= 5 and C++ >= 17 and RTTI enabled</br>
Visual Studio >= 2017 and C++ >= 17 and RTTI enabled</br>
GCC >= 7 and C++ >= 17 and RTTI enabled</br>
## `NAMEOF_FULL_TYPE_RTTI`
* Obtains full type name, using RTTI.
@ -324,3 +409,53 @@
volatile const my::detail::Base* ptr = new my::detail::Derived();
NAMEOF_SHORT_TYPE_RTTI(*ptr) -> "Derived"
```
* Compiler compatibility
Clang/LLVM >= 5 and C++ >= 17 and RTTI enabled</br>
Visual Studio >= 2017 and C++ >= 17 and RTTI enabled</br>
GCC >= 7 and C++ >= 17 and RTTI enabled</br>
## `NAMEOF_MEMBER`
* Obtains name of member.
* Returns `string_view`.
* Examples
```cpp
struct A {
int this_is_the_name;
};
// ..
NAMEOF_MEMBER(&A::this_is_the_name) -> "this_is_the_name"
nameof::nameof_member(&A::this_is_the_name) -> "this_is_the_name"
```
* Compiler compatibility
Clang/LLVM >= 5 and C++ >= 17</br>
Visual Studio >= 2022 and C++ >= 20</br>
GCC >= 7 and C++ >= 17</br>
## `NAMEOF_POINTER`
* Obtains name of a function, a global or class static variable.
* Returns `string_view`.
* Examples
```cpp
int someglobalvariable = 0;
// ..
NAMEOF_POINTER(&someglobalconstvariable) == "someglobalconstvariable"
nameof::nameof_pointer(&someglobalconstvariable) == "someglobalconstvariable"
constexpr auto global_ptr = &someglobalvariable;
NAMEOF_POINTER(global_ptr) == "someglobalconstvariable"
nameof::nameof_pointer(global_ptr) == "someglobalconstvariable"
```
* Compiler compatibility
Clang/LLVM >= 5 and C++ >= 17</br>
Visual Studio >= 2022 and C++ >= 20</br>
GCC >= 7 and C++ >= 17</br>

View file

@ -1,6 +1,6 @@
// Licensed under the MIT License <http://opensource.org/licenses/MIT>.
// SPDX-License-Identifier: MIT
// Copyright (c) 2018 - 2022 Daniil Goncharov <neargye@gmail.com>.
// Copyright (c) 2018 - 2023 Daniil Goncharov <neargye@gmail.com>.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal

View file

@ -1,6 +1,6 @@
// Licensed under the MIT License <http://opensource.org/licenses/MIT>.
// SPDX-License-Identifier: MIT
// Copyright (c) 2020 - 2022 Daniil Goncharov <neargye@gmail.com>.
// Copyright (c) 2020 - 2023 Daniil Goncharov <neargye@gmail.com>.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal

View file

@ -9,7 +9,7 @@
//
// Licensed under the MIT License <http://opensource.org/licenses/MIT>.
// SPDX-License-Identifier: MIT
// Copyright (c) 2016 - 2022 Daniil Goncharov <neargye@gmail.com>.
// Copyright (c) 2016 - 2023 Daniil Goncharov <neargye@gmail.com>.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@ -1009,7 +1009,7 @@ constexpr auto get_member_name() noexcept {
return n<V>();
} else {
constexpr bool is_defined = sizeof(decltype(get_base_type(V))) != 0;
static_assert(is_defined, "Member name can use only if the struct is already fully defined. Please use NAMEOF macro, or separate definition and declaration.");
static_assert(is_defined, "nameof::nameof_member member name can use only if the struct is already fully defined. Please use NAMEOF macro, or separate definition and declaration.");
if constexpr (is_defined) {
return n<V, &(union_type_holder<decltype(get_base_type(V))>::value.f.*V)>();
} else {
@ -1025,19 +1025,18 @@ template <auto V>
inline constexpr auto member_name_v = cstring<0>{};
#endif
template<auto U, auto V>
template <auto U, auto V>
struct is_same : std::false_type {};
template<auto U>
template <auto U>
struct is_same<U, U> : std::true_type {};
template<auto P>
template <auto P>
constexpr bool is_nullptr_v = is_same<P, static_cast<std::remove_reference_t<decltype(P)>>(nullptr)>::value;
template <auto V>
constexpr auto p() noexcept {
[[maybe_unused]] constexpr auto custom_name =
customize::pointer_name<V>().empty() && is_nullptr_v<V> ? "nullptr" : customize::pointer_name<V>();
[[maybe_unused]] constexpr auto custom_name = customize::pointer_name<V>().empty() && is_nullptr_v<V> ? "nullptr" : customize::pointer_name<V>();
if constexpr (custom_name.empty() && nameof_pointer_supported<decltype(V)>::value) {
#if defined(__clang__)

View file

@ -1,6 +1,6 @@
// Licensed under the MIT License <http://opensource.org/licenses/MIT>.
// SPDX-License-Identifier: MIT
// Copyright (c) 2018 - 2022 Daniil Goncharov <neargye@gmail.com>.
// Copyright (c) 2018 - 2023 Daniil Goncharov <neargye@gmail.com>.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal

View file

@ -1,6 +1,6 @@
// Licensed under the MIT License <http://opensource.org/licenses/MIT>.
// SPDX-License-Identifier: MIT
// Copyright (c) 2019 - 2022 Daniil Goncharov <neargye@gmail.com>.
// Copyright (c) 2019 - 2023 Daniil Goncharov <neargye@gmail.com>.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal