This commit is contained in:
Terik23 2018-03-17 08:30:45 +05:00 committed by GitHub
parent be8c1d7c21
commit 6291bc438e

View file

@ -27,6 +27,7 @@ inline constexpr const char* template_nameof_(const char* name, size_t length) {
? &name[length] ? &name[length]
: template_nameof_(name, length - 1); : template_nameof_(name, length - 1);
} }
// Used to obtain the string name of a variable. // Used to obtain the string name of a variable.
#define nameof_variable(variable) template_nameof_variable(variable, #variable, sizeof(#variable) / sizeof(char) - 1) #define nameof_variable(variable) template_nameof_variable(variable, #variable, sizeof(#variable) / sizeof(char) - 1)
template <typename T> template <typename T>
@ -40,6 +41,7 @@ template <typename T> inline constexpr const char* template_nameof_type(const ch
#define nameof_function(function) template_nameof_function(#function, sizeof(#function) / sizeof(char) - 1); if (false) (void)(function); #define nameof_function(function) template_nameof_function(#function, sizeof(#function) / sizeof(char) - 1); if (false) (void)(function);
inline constexpr const char* template_nameof_function(const char* name, size_t length) { return template_nameof_(name, length); } inline constexpr const char* template_nameof_function(const char* name, size_t length) { return template_nameof_(name, length); }
// Example.
#include <iostream> #include <iostream>
struct SomeStruct { struct SomeStruct {