From 60779d13660f36e9cf289558794706272d486902 Mon Sep 17 00:00:00 2001 From: Neargye Date: Sat, 14 Apr 2018 23:47:14 +0500 Subject: [PATCH] add macros support --- include/nameof.hpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/include/nameof.hpp b/include/nameof.hpp index b6683ba..90bdd6b 100644 --- a/include/nameof.hpp +++ b/include/nameof.hpp @@ -32,9 +32,6 @@ #include -#define NAMEOF_RAW_(x) #x -#define NAMEOF_RAW(x) NAMEOF_RAW_(x) - namespace nameof { namespace detail { @@ -56,18 +53,18 @@ inline constexpr const char* Nameof(const char* name, const std::size_t length, #if defined(__GNUC__) || defined(__clang__) -// Used to obtain the string name of a variable, type, function and etc. -#define NAMEOF(name) ::nameof::Nameof(NAMEOF_RAW(name), sizeof(NAMEOF_RAW(name)) / sizeof(char) - 1, sizeof(void(*)(__typeof__(name)))) +// Used to obtain the string name of a variable, type, function, macros and etc. +#define NAMEOF(name) ::nameof::Nameof(#name, sizeof(#name) / sizeof(char) - 1, sizeof(void(*)(__typeof__(name)))) -// Used to obtain the string full name of a variable, type, function and etc. -#define NAMEOF_FULL(name) ::nameof::Nameof(NAMEOF_RAW(name), 0, sizeof(void(*)(__typeof__(name)))) +// Used to obtain the string full name of a variable, type, function, macros and etc. +#define NAMEOF_FULL(name) ::nameof::Nameof(#name, 0, sizeof(void(*)(__typeof__(name)))) #else -// Used to obtain the string name of a variable, type, function and etc. -#define NAMEOF(name) ::nameof::Nameof(NAMEOF_RAW(name), sizeof(NAMEOF_RAW(name)) / sizeof(char) - 1, sizeof(typeid(name))) +// Used to obtain the string name of a variable, type, function, macros and etc. +#define NAMEOF(name) ::nameof::Nameof(#name, sizeof(#name) / sizeof(char) - 1, sizeof(typeid(name))) -// Used to obtain the string full name of a variable, type, function and etc. -#define NAMEOF_FULL(name) ::nameof::Nameof(NAMEOF_RAW(name), 0, sizeof(typeid(name))) +// Used to obtain the string full name of a variable, type, function, macros and etc. +#define NAMEOF_FULL(name) ::nameof::Nameof(#name, 0, sizeof(typeid(name))) #endif