From efb385e901de93298f151f81c0146184678d1fd7 Mon Sep 17 00:00:00 2001 From: Terik23 Date: Sat, 17 Mar 2018 14:53:33 +0500 Subject: [PATCH] Clean up and add new test --- example/example.cpp | 8 +++++++- src/nameof.hpp | 15 +++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/example/example.cpp b/example/example.cpp index ffbe8f1..7cfac34 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -38,6 +38,10 @@ struct Long { LL LLField; }; +struct TestRValue { + int Field; +}; + int someVar = 0; int main() { @@ -62,9 +66,11 @@ int main() { std::cout << NAMEOF_VAR(&SomeStruct::SomeMethod) << std::endl; // SomeMethod std::cout << NAMEOF_VAR(otherVar.LLField.LLLField) << std::endl; // LLLField std::cout << NAMEOF_VAR(&someVar) << std::endl; // someVar + std::cout << NAMEOF_VAR(ptrVar) << std::endl; // ptrVar std::cout << NAMEOF_VAR(*ptrVar) << std::endl; // ptrVar std::cout << NAMEOF_VAR(+innValue) << std::endl; // innValue std::cout << NAMEOF_VAR(-innValue) << std::endl; // innValue std::cout << NAMEOF_VAR(~innValue) << std::endl; // innValue - std::cout << NAMEOF_VAR(!innValue) << std::endl; // unsignedValue + std::cout << NAMEOF_VAR(!innValue) << std::endl; // innValue + std::cout << NAMEOF_VAR(TestRValue()) << std::endl; // TestRValue() } \ No newline at end of file diff --git a/src/nameof.hpp b/src/nameof.hpp index 2d11d8f..327a626 100644 --- a/src/nameof.hpp +++ b/src/nameof.hpp @@ -26,16 +26,11 @@ inline constexpr const char* template_nameof(const char* name, const size_t length) { return length == 0 ? name - : (name[length - 1] == ' ' || - name[length - 1] == '.' || - name[length - 1] == '>' || - name[length - 1] == ':' || - name[length - 1] == '&' || - name[length - 1] == '*' || - name[length - 1] == '+' || - name[length - 1] == '~' || - name[length - 1] == '-' || - name[length - 1] == '!') + : (name[length - 1] == ' ' || name[length - 1] == '.' || + name[length - 1] == '>' || name[length - 1] == ':' || + name[length - 1] == '&' || name[length - 1] == '*' || + name[length - 1] == '+' || name[length - 1] == '~' || + name[length - 1] == '-' || name[length - 1] == '!') ? &name[length] : template_nameof(name, length - 1); }