This commit is contained in:
terik23 2019-03-22 09:46:37 +05:00
parent 8d49ed040b
commit 1aa2d1ad66
3 changed files with 6 additions and 6 deletions

View file

@ -15,7 +15,7 @@ master |[![Build Status](https://travis-ci.org/Neargye/nameof.svg?branch=master)
## What is Nameof? ## What is Nameof?
A header only C++17 library provides nameof macros and functions to obtain the simple name of variable, type, function, macros and enum. A header only C++17 library provides nameof macros and functions to obtain the simple name of variable, type, function, macro and enum.
Before, you had to use string literals to refer to definitions, which is brittle when renaming code elements because tools do not know to check these string literals. Before, you had to use string literals to refer to definitions, which is brittle when renaming code elements because tools do not know to check these string literals.
@ -80,7 +80,7 @@ constexpr auto cx_name = NAMEOF_TYPE(Color::RED);
static_assert("Color" == cx_name); static_assert("Color" == cx_name);
``` ```
* Name of macros * Name of macro
```cpp ```cpp
NAMEOF(__LINE__) -> "__LINE__" NAMEOF(__LINE__) -> "__LINE__"

View file

@ -260,13 +260,13 @@ constexpr std::string_view nameof_type(T) noexcept {
} // namespace nameof } // namespace nameof
// Used to obtain the simple (unqualified) string name of a variable, member, function, enum, macros. // Used to obtain the simple (unqualified) string name of a variable, member, function, enum, macro.
#define NAMEOF(...) ::nameof::detail::nameof_impl<decltype(__VA_ARGS__)>(#__VA_ARGS__, false) #define NAMEOF(...) ::nameof::detail::nameof_impl<decltype(__VA_ARGS__)>(#__VA_ARGS__, false)
// Used to obtain the full string name of a variable, member, function, enum, macros. // Used to obtain the full string name of a variable, member, function, enum, macro.
#define NAMEOF_FULL(...) ::nameof::detail::nameof_impl<decltype(__VA_ARGS__)>(#__VA_ARGS__, true) #define NAMEOF_FULL(...) ::nameof::detail::nameof_impl<decltype(__VA_ARGS__)>(#__VA_ARGS__, true)
// Used to obtain the raw string name of a variable, member, function, enum, macros. // Used to obtain the raw string name of a variable, member, function, enum, macro.
#define NAMEOF_RAW(...) ::nameof::detail::nameof_raw_impl<decltype(__VA_ARGS__)>(#__VA_ARGS__) #define NAMEOF_RAW(...) ::nameof::detail::nameof_raw_impl<decltype(__VA_ARGS__)>(#__VA_ARGS__)
// Used to obtain the simple (unqualified) string name of a enum variable. // Used to obtain the simple (unqualified) string name of a enum variable.

View file

@ -196,7 +196,7 @@ TEST_CASE("NAMEOF_RAW") {
REQUIRE(NAMEOF_RAW(Color::BLUE) == "Color::BLUE"); REQUIRE(NAMEOF_RAW(Color::BLUE) == "Color::BLUE");
} }
SECTION("macros") { SECTION("macro") {
REQUIRE(NAMEOF_RAW(__cplusplus) == "__cplusplus"); REQUIRE(NAMEOF_RAW(__cplusplus) == "__cplusplus");
REQUIRE(NAMEOF_RAW(__LINE__) == "__LINE__"); REQUIRE(NAMEOF_RAW(__LINE__) == "__LINE__");
REQUIRE(NAMEOF_RAW(__FILE__) == "__FILE__"); REQUIRE(NAMEOF_RAW(__FILE__) == "__FILE__");