From 713a504d5f4a431cbd63cbbad9b2f5e3cf4c209e Mon Sep 17 00:00:00 2001 From: Neargye Date: Sat, 14 Jul 2018 04:51:17 +0500 Subject: [PATCH] clean-up --- example/example.cpp | 10 +--------- include/nameof.hpp | 4 ++-- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/example/example.cpp b/example/example.cpp index 1ce0549..d18f79e 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -70,7 +70,6 @@ SomeStruct somevar; Long othervar; int intvar = 0; SomeStruct* ptrvar = &somevar; -SomeStruct** ptrptrvar = &ptrvar; int main() { // constexpr @@ -90,13 +89,6 @@ int main() { std::cout << NAMEOF((&somevar)->somefield) << std::endl; // somefield std::cout << NAMEOF(othervar.ll.field) << std::endl; // field - // variable - std::cout << NAMEOF(ptrvar) << std::endl; // ptrvar - std::cout << NAMEOF(*ptrvar) << std::endl; // ptrvar - std::cout << NAMEOF(ptrptrvar) << std::endl; // ptrptrvar - std::cout << NAMEOF(*ptrptrvar) << std::endl; // ptrptrvar - std::cout << NAMEOF(**ptrptrvar) << std::endl; // ptrptrvar - // function std::cout << NAMEOF(&SomeStruct::SomeMethod2) << std::endl; // SomeMethod2 std::cout << NAMEOF(SomeMethod3) << std::endl; // SomeMethod3 @@ -115,7 +107,6 @@ int main() { std::cout << NAMEOF_FULL(somevar.somefield) << std::endl; // somevar.somefield std::cout << NAMEOF_FULL(&SomeStruct::SomeMethod2) << std::endl; // &SomeStruct::SomeMethod2 std::cout << NAMEOF_FULL(Long::LL) << std::endl; // Long::LL - std::cout << NAMEOF_FULL(std::string) << std::endl; // std::string const auto div = [](int x, int y) -> int { if (y == 0) { @@ -156,6 +147,7 @@ int main() { std::cout << NAMEOF(std::cout << intvar << std::endl) << std::endl; // 'endl' std::cout << NAMEOF(decltype(intvar)) << std::endl; // 'decltype(intvar)' std::cout << NAMEOF(typeid(intvar)) << std::endl; // 'typeid(intvar)' + std::cout << NAMEOF((intvar)) << std::endl; // '(intvar)' return 0; } diff --git a/include/nameof.hpp b/include/nameof.hpp index ffee928..a4db4ea 100644 --- a/include/nameof.hpp +++ b/include/nameof.hpp @@ -37,14 +37,14 @@ namespace nameof { namespace detail { -inline constexpr bool IsLexeme(const char s) noexcept { +inline constexpr bool IsLexeme(char s) noexcept { return (s == '.' || s == '>' || s == ':' || s == '&' || s == '*' || s == '+' || s == '~' || s == '-' || s == '!'); } } // namespace detail -inline constexpr const char* Nameof(const char* name, const std::size_t length) noexcept { +inline constexpr const char* Nameof(const char* name, std::size_t length) noexcept { return ((length == 0) ? name : (detail::IsLexeme(name[length - 1]) ? &name[length] : Nameof(name, length - 1)));