From dd1bf76e65bbb58689f411d9b70db66fc040345e Mon Sep 17 00:00:00 2001 From: Terik23 Date: Sun, 9 Oct 2016 20:27:12 +0500 Subject: [PATCH] --- nameof.cpp | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/nameof.cpp b/nameof.cpp index 914cc1d..4b58665 100644 --- a/nameof.cpp +++ b/nameof.cpp @@ -1,13 +1,24 @@ ///Used to obtain the string name of a variable. - -#define nameof(name) template_nameof((name), #name) +#define nameof_variable(name) template_nameof_variable(name, #name) template -const char* template_nameof(const T& validate_type, const char* name) +const char* template_nameof_variable(const T& validate_type, const char* name) +{ + return name; +} +///Used to obtain the string name of a type. +#define nameof_type(name) template_nameof_type(#name) + +template +const char* template_nameof_type(const char* name) { return name; } -// int test = 0; -// std::cout << nameof(test) << std::endl; -// prints "test” \ No newline at end of file +//example +int test = 0; +std::cout << nameof_variable(test) << " " << nameof_type(int) << std::endl; +// prints "test int” +std::string test_wrong; +std::cout << nameof_variable(static_cast(test_wrong.c_str())) << " " << nameof_type(std::string) << std::endl; +// prints "static_cast(test_wrong.c_str()) std::string" \ No newline at end of file