From 5e0024145c4c3e88e6ce53e3cd101ee6f196fdaa Mon Sep 17 00:00:00 2001 From: Neargye Date: Mon, 27 Aug 2018 04:57:25 +0500 Subject: [PATCH] wip --- example/example.cpp | 14 ++- include/nameof.hpp | 133 +++++++++++------------- test/test.cpp | 242 +++++++++++++------------------------------- 3 files changed, 141 insertions(+), 248 deletions(-) diff --git a/example/example.cpp b/example/example.cpp index 45c4b16..5ed1905 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -102,20 +102,24 @@ int main() { std::cout << NAMEOF(&SomeStruct::SomeMethod1) << std::endl; // SomeMethod1 std::cout << NAMEOF(&SomeStruct::SomeMethod2) << std::endl; // SomeMethod2 std::cout << NAMEOF(SomeMethod3) << std::endl; // SomeMethod3 + std::cout << NAMEOF(SomeMethod4) << std::endl; // SomeMethod4 + std::cout << NAMEOF_FULL(SomeMethod4) << std::endl; // SomeMethod4 + std::cout << NAMEOF(&SomeClass::SomeMethod5) << std::endl; // SomeMethod5 + std::cout << NAMEOF(&SomeClass::SomeMethod6) << std::endl; // SomeMethod6 + std::cout << NAMEOF_FULL(&SomeClass::SomeMethod6) << std::endl; // SomeMethod6 // Type name. std::cout << NAMEOF_TYPE(structvar) << std::endl; // SomeStruct std::cout << NAMEOF_TYPE(othervar.ll) << std::endl; // LL std::cout << NAMEOF_TYPE(SomeClass{}) << std::endl; // SomeClass - std::cout << NAMEOF_TYPE_T(std::string) << std::endl; // basic_string + std::cout << NAMEOF_TYPE(othervar.ll) << std::endl; // Long::LL + std::cout << NAMEOF_TYPE(std::declval>()) << std::endl; // const SomeClass && - // Type full name. - std::cout << NAMEOF_TYPE_RAW(othervar.ll) << std::endl; // Long::LL - std::cout << NAMEOF_TYPE_RAW(std::declval>()) << std::endl; // const SomeClass && - std::cout << NAMEOF_TYPE_RAW_T(const SomeClass volatile *) << std::endl; // const volatile SomeClass * + std::cout << NAMEOF_TYPE_T(const SomeClass volatile *) << std::endl; // const volatile SomeClass * + std::cout << NAMEOF_TYPE_T(SomeClass) << std::endl; // SomeClass // Raw name. std::cout << NAMEOF_RAW(volatile const int) << std::endl; // volatile const int diff --git a/include/nameof.hpp b/include/nameof.hpp index 1d54d2c..88a4146 100644 --- a/include/nameof.hpp +++ b/include/nameof.hpp @@ -39,6 +39,13 @@ # define NAMEOF_HAS_CONSTEXPR14 1 #endif +#if defined(__clang__) || defined(_MSC_VER) +# define NAMEOF_TYPE_CONSTEXPR constexpr +# define NAMEOF_TYPE_HAS_CONSTEXPR 1 +#else +# define NAMEOF_TYPE_CONSTEXPR inline +#endif + namespace nameof { namespace detail { @@ -189,17 +196,16 @@ class cstring final { return {str_ + pos, n}; } - friend constexpr bool operator==(const cstring& lhs, const cstring& rhs) noexcept { + friend constexpr bool operator==(cstring lhs, cstring rhs) noexcept { return (lhs.size_ == rhs.size_) && StrEquals(lhs.str_, rhs.str_, lhs.size_); } - friend constexpr bool operator!=(const cstring& lhs, const cstring& rhs) noexcept { + friend constexpr bool operator!=(cstring lhs, cstring rhs) noexcept { return !(lhs == rhs); } - friend std::ostream& operator<<(std::ostream& os, const cstring& str) { + friend std::ostream& operator<<(std::ostream& os, cstring str) { os.write(str.str_, str.size_); - os.write("!", 1); return os; } @@ -211,7 +217,7 @@ constexpr bool IsLexeme(char s) noexcept { } #if defined(NAMEOF_HAS_CONSTEXPR14) -constexpr cstring NameofBase(const cstring& name, bool with_suffix) noexcept { +constexpr cstring NameofPretty(cstring name, bool with_suffix) noexcept { std::size_t s = 0; for (std::size_t i = name.size(), h = 0; i > 0; --i) { if (name[i - 1] == '>') { @@ -226,13 +232,11 @@ constexpr cstring NameofBase(const cstring& name, bool with_suffix) noexcept { continue; } - if (h != 0) { - ++s; - continue; - } - if (h == 0) { break; + } else { + ++s; + continue; } } @@ -241,10 +245,11 @@ constexpr cstring NameofBase(const cstring& name, bool with_suffix) noexcept { return name.remove_prefix(i).remove_suffix(with_suffix ? 0 : s); } } + return name.remove_suffix(with_suffix ? 0 : s); } #else -constexpr std::size_t NameofBaseImpl1(const cstring& name, std::size_t h = 0, std::size_t s = 0) noexcept { +constexpr std::size_t NameofBaseImpl1(cstring name, std::size_t h = 0, std::size_t s = 0) noexcept { return name[name.size() - 1 - s] == '>' ? NameofBaseImpl1(name, h + 1, s + 1) : name[name.size() - 1 - s] == '<' @@ -252,102 +257,94 @@ constexpr std::size_t NameofBaseImpl1(const cstring& name, std::size_t h = 0, st : h == 0 ? s : NameofBaseImpl1(name, h, s + 1); } -constexpr cstring NameofBaseImpl2(const cstring& name, const std::size_t p = 0) noexcept { +constexpr cstring NameofBaseImpl2(cstring name, const std::size_t p = 0) noexcept { return p == name.size() ? name : IsLexeme(name[name.size() - 1 - p]) ? name.remove_prefix(name.size() - p) : NameofBaseImpl2(name, p + 1); } -constexpr cstring NameofBaseImpl3(const cstring& name, std::size_t s, bool with_suffix) noexcept { +constexpr cstring NameofBaseImpl3(cstring name, std::size_t s, bool with_suffix) noexcept { return NameofBaseImpl2(name.remove_suffix(s)).add_suffix(with_suffix ? s : 0); } -constexpr cstring NameofBase(const cstring& name, bool with_suffix) noexcept { +constexpr cstring NameofPretty(cstring name, bool with_suffix) noexcept { return NameofBaseImpl3(name, NameofBaseImpl1(name), with_suffix); } #endif -constexpr cstring RemoveSpace(const cstring& name) noexcept { +constexpr cstring RemoveSpace(cstring name) noexcept { return name.back() == ' ' ? RemoveSpace(name.remove_suffix(1)) : name; } -constexpr cstring RemoveClassPrefix(const cstring& name) noexcept { +constexpr cstring RemoveClassPrefix(cstring name) noexcept { return (name.size() > sizeof("class") && name[0] == 'c' && name[1] == 'l' && name[2] == 'a' && name[3] == 's' && name[4] == 's' && name[5] == ' ') ? name.remove_prefix(sizeof("class")) : name; } -constexpr cstring RemoveEnumPrefix(const cstring& name) noexcept { +constexpr cstring RemoveEnumPrefix(cstring name) noexcept { return (name.size() > sizeof("enum") && name[0] == 'e' && name[1] == 'n' && name[2] == 'u' && name[3] == 'm' && name[4] == ' ') ? name.remove_prefix(sizeof("enum")) : name; } -constexpr cstring RemoveStructPrefix(const cstring& name) noexcept { +constexpr cstring RemoveStructPrefix(cstring name) noexcept { return (name.size() > sizeof("struct") && name[0] == 's' && name[1] == 't' && name[2] == 'r' && name[3] == 'u' && name[4] == 'c' && name[5] == 't' && name[6] == ' ') ? name.remove_prefix(sizeof("struct")) : name; } -constexpr cstring NameofTypeRawImpl(const cstring& name, bool raw) noexcept { - return raw - ? name - : RemoveClassPrefix(RemoveStructPrefix(RemoveEnumPrefix(RemoveSpace(name)))); +constexpr cstring NameofTypeRawPretty(cstring name) noexcept { + return RemoveClassPrefix(RemoveStructPrefix(RemoveEnumPrefix(RemoveSpace(name)))); } -} // namespace detail +template +NAMEOF_TYPE_CONSTEXPR cstring NameofTypeRaw() noexcept { +#if defined(__clang__) + return {__PRETTY_FUNCTION__, + sizeof(__PRETTY_FUNCTION__) - 1, + sizeof("nameof::detail::cstring nameof::detail::NameofTypeRaw() [T = nameof::detail::nstd::identity<") - 1, + sizeof(">]") - 1}; +#elif defined(__GNUC__) + return {__PRETTY_FUNCTION__, + sizeof(__PRETTY_FUNCTION__) - 1, + sizeof("nameof::detail::cstring nameof::detail::NameofTypeRaw() [with T = nameof::detail::nstd::identity<") - 1, + sizeof(">]") - 1}; +#elif defined(_MSC_VER) + return {__FUNCSIG__, + sizeof(__FUNCSIG__) - 1, + sizeof("class nameof::detail::cstring __cdecl nameof::detail::NameofTypeRaw>(void) noexcept") - 1}; +#else + return {}; +#endif +} template ::value && !std::is_void::value>::type> -constexpr detail::cstring Nameof(const T&, const char* name, std::size_t size, bool with_suffix) noexcept { - return detail::NameofBase({name, size}, with_suffix); +constexpr cstring Nameof(const T&, const char* name, std::size_t size, bool with_suffix) noexcept { + return NameofPretty({name, size}, with_suffix); } template ::value && !std::is_function::value && !std::is_member_function_pointer::value>::type> -constexpr detail::cstring Nameof(T&&, const char*, std::size_t, bool) = delete; +constexpr cstring Nameof(T&&, const char*, std::size_t, bool) = delete; -constexpr detail::cstring NameofRaw(const char* name, std::size_t size) noexcept { +constexpr cstring NameofRaw(const char* name, std::size_t size) noexcept { return {name, size}; } -template -constexpr detail::cstring NameofTypeRaw(bool raw = false) noexcept { -#if defined(__clang__) - return detail::NameofTypeRawImpl( - {__PRETTY_FUNCTION__, - sizeof(__PRETTY_FUNCTION__) - 1, - sizeof("detail::cstring nameof::NameofTypeRaw(bool) [T = nameof::detail::nstd::identity<") - 1, - sizeof(">]") - 1}, - raw); -#elif defined(__GNUC__) - return detail::NameofTypeRawImpl( - {__PRETTY_FUNCTION__, - sizeof(__PRETTY_FUNCTION__) - 1, - sizeof("constexpr nameof::detail::cstring nameof::NameofTypeRaw(bool) [with T = nameof::detail::nstd::identity<") - 1, - sizeof(">]") - 1}, - raw); -#elif defined(_MSC_VER) - return detail::NameofTypeRawImpl( - {__FUNCSIG__, - sizeof(__FUNCSIG__) - 1, - sizeof("class nameof::detail::cstring __cdecl nameof::NameofTypeRaw>(bool) noexcept") - 1}, - raw); -#else - return {}; -#endif -} +} // namespace detail -template >> -constexpr detail::cstring NameofType(bool with_suffix = false) noexcept { - return detail::NameofBase(NameofTypeRaw(), with_suffix); +template > +NAMEOF_TYPE_CONSTEXPR detail::cstring NameofType(bool pretty = true) noexcept { + return pretty ? detail::NameofTypeRawPretty(detail::NameofTypeRaw()) : detail::NameofTypeRaw(); } } // namespace nameof @@ -370,26 +367,18 @@ constexpr detail::cstring NameofType(bool with_suffix = false) noexcept { #include // Used to obtain the raw string name of a variable, type, member, function, macros. -# define NAMEOF_RAW(name) ::nameof::NameofRaw(#name, ((sizeof(#name) / sizeof(char)) - 1) + (0 * sizeof(typeid(name)))) +# define NAMEOF_RAW(name) ::nameof::detail::NameofRaw(#name, ((sizeof(#name) / sizeof(char)) - 1) + (0 * sizeof(typeid(name)))) #elif defined(__clang__) || defined(__GNUC__) // Used to obtain the raw string name of a variable, type, member, function, macros. -# define NAMEOF_RAW(name) ::nameof::NameofRaw(#name, ((sizeof(#name) / sizeof(char)) - 1) + (0 * sizeof(void(*)(__typeof__(name))))) +# define NAMEOF_RAW(name) ::nameof::detail::NameofRaw(#name, ((sizeof(#name) / sizeof(char)) - 1) + (0 * sizeof(void(*)(__typeof__(name))))) #endif // Used to obtain the simple (unqualified) string name of a variable, member, function. -#define NAMEOF(name) ::nameof::Nameof(name, #name, (sizeof(#name) / sizeof(char)) - 1, false) +#define NAMEOF(name) ::nameof::detail::Nameof(name, #name, (sizeof(#name) / sizeof(char)) - 1, false) // Used to obtain the full string name of a variable, member, function. -#define NAMEOF_FULL(name) ::nameof::Nameof(name, #name, (sizeof(#name) / sizeof(char)) - 1, true) +#define NAMEOF_FULL(name) ::nameof::detail::Nameof(name, #name, (sizeof(#name) / sizeof(char)) - 1, true) -// Used to obtain the simple (unqualified) string name of a type. -#define NAMEOF_TYPE(var) ::nameof::NameofType(false) -#define NAMEOF_TYPE_T(type) ::nameof::NameofType(false) - -// Used to obtain the full string name of a type. -#define NAMEOF_TYPE_FULL(var) ::nameof::NameofType(true) -#define NAMEOF_TYPE_FULL_T(type) ::nameof::NameofType(true) - -// Used to obtain the raw string name of a type. -#define NAMEOF_TYPE_RAW(var) ::nameof::NameofTypeRaw<::nameof::detail::nstd::identity>(false) -#define NAMEOF_TYPE_RAW_T(type) ::nameof::NameofTypeRaw<::nameof::detail::nstd::identity>(false) +// Used to obtain the string name of a type. +#define NAMEOF_TYPE(var) ::nameof::NameofType(true) +#define NAMEOF_TYPE_T(type) ::nameof::NameofType(true) diff --git a/test/test.cpp b/test/test.cpp index 3196de4..b61caab 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -128,38 +128,18 @@ TEST_CASE("constexpr") { static_assert(cx6 == "__cplusplus", ""); } - // constexpr in NAMEOF_TYPE not supported if GCC. + // constexpr NAMEOF_TYPE not supported in GCC. #if defined(_MSC_VER) || defined(__clang__) SECTION("NAMEOF_TYPE") { constexpr auto cx = NAMEOF_TYPE(classvar); - static_assert(cx == "SomeClass", ""); - } - - SECTION("NAMEOF_TYPE") { - constexpr auto cx = NAMEOF_TYPE_T(const SomeClass volatile *); - static_assert(cx == "SomeClass", ""); - } - - SECTION("NAMEOF_TYPE_FULL") { - constexpr auto cx = NAMEOF_TYPE_FULL(classvar); - static_assert(cx == "SomeClass", ""); - } - - SECTION("NAMEOF_TYPE_FULL") { - constexpr auto cx = NAMEOF_TYPE_FULL_T(const SomeClass volatile *); - static_assert(cx == "SomeClass", ""); - } - - SECTION("NAMEOF_TYPE_RAW") { - constexpr auto cx = NAMEOF_TYPE_RAW(classvar); #if defined(__clang__) static_assert(cx == "const volatile SomeClass *", ""); #elif defined(_MSC_VER) static_assert(cx == "SomeClass const volatile *", ""); #endif } - SECTION("NAMEOF_TYPE_RAW") { - constexpr auto cx = NAMEOF_TYPE_RAW_T(const SomeClass volatile *); + SECTION("NAMEOF_TYPE_T") { + constexpr auto cx = NAMEOF_TYPE_T(const SomeClass volatile *); #if defined(__clang__) static_assert(cx == "const volatile SomeClass *", ""); #elif defined(_MSC_VER) @@ -274,175 +254,103 @@ TEST_CASE("NAMEOF_RAW") { } TEST_CASE("NAMEOF_TYPE") { +#if defined(__clang__) REQUIRE(NAMEOF_TYPE(structvar) == "SomeStruct"); - REQUIRE(NAMEOF_TYPE(ptrvar) == "SomeStruct"); - REQUIRE(NAMEOF_TYPE(refvar) == "SomeStruct"); + REQUIRE(NAMEOF_TYPE(ptrvar) == "SomeStruct *"); + REQUIRE(NAMEOF_TYPE(refvar) == "SomeStruct &"); - REQUIRE(NAMEOF_TYPE(classvar) == "SomeClass"); - REQUIRE(NAMEOF_TYPE(std::declval volatile *>()) == "SomeClass"); + REQUIRE(NAMEOF_TYPE(classvar) == "const volatile SomeClass *"); REQUIRE(NAMEOF_TYPE(othervar) == "Long"); - REQUIRE(NAMEOF_TYPE(othervar.ll) == "LL"); + REQUIRE(NAMEOF_TYPE(othervar.ll) == "Long::LL"); REQUIRE(NAMEOF_TYPE(othervar.ll.field) == "int"); - REQUIRE(NAMEOF_TYPE(std::string{}) == "basic_string"); + REQUIRE(NAMEOF_TYPE(Color::RED) == "Color"); + + REQUIRE(NAMEOF_TYPE(std::declval>()) == "const SomeClass &&"); +#elif defined(_MSC_VER) + REQUIRE(NAMEOF_TYPE(structvar) == "SomeStruct"); + REQUIRE(NAMEOF_TYPE(ptrvar) == "SomeStruct *"); + REQUIRE(NAMEOF_TYPE(refvar) == "SomeStruct &"); + + REQUIRE(NAMEOF_TYPE(classvar) == "SomeClass const volatile *"); + + REQUIRE(NAMEOF_TYPE(othervar) == "Long"); + REQUIRE(NAMEOF_TYPE(othervar.ll) == "Long::LL"); + REQUIRE(NAMEOF_TYPE(othervar.ll.field) == "int"); REQUIRE(NAMEOF_TYPE(Color::RED) == "Color"); -} -TEST_CASE("NAMEOF_TYPE_T") { - REQUIRE(NAMEOF_TYPE_T(decltype(structvar)) == "SomeStruct"); - REQUIRE(NAMEOF_TYPE_T(decltype(ptrvar)) == "SomeStruct"); - REQUIRE(NAMEOF_TYPE_T(decltype(refvar)) == "SomeStruct"); - REQUIRE(NAMEOF_TYPE_T(SomeStruct) == "SomeStruct"); - REQUIRE(NAMEOF_TYPE_T(SomeStruct *) == "SomeStruct"); - REQUIRE(NAMEOF_TYPE_T(SomeStruct &) == "SomeStruct"); - REQUIRE(NAMEOF_TYPE_T(const SomeStruct volatile *) == "SomeStruct"); - - REQUIRE(NAMEOF_TYPE_T(SomeClass) == "SomeClass"); - REQUIRE(NAMEOF_TYPE_T(const SomeClass volatile *) == "SomeClass"); - - REQUIRE(NAMEOF_TYPE_T(decltype(othervar)) == "Long"); - REQUIRE(NAMEOF_TYPE_T(Long) == "Long"); - REQUIRE(NAMEOF_TYPE_T(Long::LL) == "LL"); - - REQUIRE(NAMEOF_TYPE_T(std::string) == "basic_string"); - - REQUIRE(NAMEOF_TYPE_T(Color) == "Color"); -} - -TEST_CASE("NAMEOF_TYPE_FULL") { - REQUIRE(NAMEOF_TYPE_FULL(structvar) == "SomeStruct"); - REQUIRE(NAMEOF_TYPE_FULL(ptrvar) == "SomeStruct"); - REQUIRE(NAMEOF_TYPE_FULL(refvar) == "SomeStruct"); - - REQUIRE(NAMEOF_TYPE_FULL(classvar) == "SomeClass"); - REQUIRE(NAMEOF_TYPE_FULL(std::declval volatile *>()) == "SomeClass"); - - REQUIRE(NAMEOF_TYPE_FULL(othervar) == "Long"); - REQUIRE(NAMEOF_TYPE_FULL(othervar.ll) == "LL"); - REQUIRE(NAMEOF_TYPE_FULL(othervar.ll.field) == "int"); - - REQUIRE(NAMEOF_TYPE_FULL(Color::RED) == "Color"); -} - -TEST_CASE("NAMEOF_TYPE_FULL_T") { - REQUIRE(NAMEOF_TYPE_FULL_T(decltype(structvar)) == "SomeStruct"); - REQUIRE(NAMEOF_TYPE_FULL_T(decltype(ptrvar)) == "SomeStruct"); - REQUIRE(NAMEOF_TYPE_FULL_T(decltype(refvar)) == "SomeStruct"); - REQUIRE(NAMEOF_TYPE_FULL_T(SomeStruct) == "SomeStruct"); - REQUIRE(NAMEOF_TYPE_FULL_T(SomeStruct *) == "SomeStruct"); - REQUIRE(NAMEOF_TYPE_FULL_T(SomeStruct &) == "SomeStruct"); - REQUIRE(NAMEOF_TYPE_FULL_T(const SomeStruct volatile *) == "SomeStruct"); - - REQUIRE(NAMEOF_TYPE_FULL_T(SomeClass) == "SomeClass"); - REQUIRE(NAMEOF_TYPE_FULL_T(const SomeClass volatile *) == "SomeClass"); - - REQUIRE(NAMEOF_TYPE_FULL_T(decltype(othervar)) == "Long"); - REQUIRE(NAMEOF_TYPE_FULL_T(Long) == "Long"); - REQUIRE(NAMEOF_TYPE_FULL_T(Long::LL) == "LL"); - - REQUIRE(NAMEOF_TYPE_FULL_T(Color) == "Color"); -} - -TEST_CASE("NAMEOF_TYPE_RAW") { -#if defined(__clang__) - REQUIRE(NAMEOF_TYPE_RAW(structvar) == "SomeStruct"); - REQUIRE(NAMEOF_TYPE_RAW(ptrvar) == "SomeStruct *"); - REQUIRE(NAMEOF_TYPE_RAW(refvar) == "SomeStruct &"); - - REQUIRE(NAMEOF_TYPE_RAW(classvar) == "const volatile SomeClass *"); - - REQUIRE(NAMEOF_TYPE_RAW(othervar) == "Long"); - REQUIRE(NAMEOF_TYPE_RAW(othervar.ll) == "Long::LL"); - REQUIRE(NAMEOF_TYPE_RAW(othervar.ll.field) == "int"); - - REQUIRE(NAMEOF_TYPE_RAW(Color::RED) == "Color"); - - REQUIRE(NAMEOF_TYPE_RAW(std::declval>()) == "const SomeClass &&"); -#elif defined(_MSC_VER) - REQUIRE(NAMEOF_TYPE_RAW(structvar) == "SomeStruct"); - REQUIRE(NAMEOF_TYPE_RAW(ptrvar) == "SomeStruct *"); - REQUIRE(NAMEOF_TYPE_RAW(refvar) == "SomeStruct &"); - - REQUIRE(NAMEOF_TYPE_RAW(classvar) == "SomeClass const volatile *"); - - REQUIRE(NAMEOF_TYPE_RAW(othervar) == "Long"); - REQUIRE(NAMEOF_TYPE_RAW(othervar.ll) == "Long::LL"); - REQUIRE(NAMEOF_TYPE_RAW(othervar.ll.field) == "int"); - - REQUIRE(NAMEOF_TYPE_RAW(Color::RED) == "Color"); - - REQUIRE(NAMEOF_TYPE_RAW(std::declval>()) == "SomeClass const &&"); + REQUIRE(NAMEOF_TYPE(std::declval>()) == "SomeClass const &&"); #elif defined(__GNUC__) - REQUIRE(NAMEOF_TYPE_RAW(structvar) == "SomeStruct"); - REQUIRE(NAMEOF_TYPE_RAW(ptrvar) == "SomeStruct*"); - REQUIRE(NAMEOF_TYPE_RAW(refvar) == "SomeStruct&"); + REQUIRE(NAMEOF_TYPE(structvar) == "SomeStruct"); + REQUIRE(NAMEOF_TYPE(ptrvar) == "SomeStruct*"); + REQUIRE(NAMEOF_TYPE(refvar) == "SomeStruct&"); - REQUIRE(NAMEOF_TYPE_RAW(classvar) == "const volatile SomeClass*"); + REQUIRE(NAMEOF_TYPE(classvar) == "const volatile SomeClass*"); - REQUIRE(NAMEOF_TYPE_RAW(othervar) == "Long"); - REQUIRE(NAMEOF_TYPE_RAW(othervar.ll) == "Long::LL"); - REQUIRE(NAMEOF_TYPE_RAW(othervar.ll.field) == "int"); + REQUIRE(NAMEOF_TYPE(othervar) == "Long"); + REQUIRE(NAMEOF_TYPE(othervar.ll) == "Long::LL"); + REQUIRE(NAMEOF_TYPE(othervar.ll.field) == "int"); - REQUIRE(NAMEOF_TYPE_RAW(Color::RED) == "Color"); + REQUIRE(NAMEOF_TYPE(Color::RED) == "Color"); - REQUIRE(NAMEOF_TYPE_RAW(std::declval>()) == "const SomeClass&&"); + REQUIRE(NAMEOF_TYPE(std::declval>()) == "const SomeClass&&"); #endif } -TEST_CASE("NAMEOF_TYPE_RAW_T") { +TEST_CASE("NAMEOF_TYPE_T") { #if defined(__clang__) - REQUIRE(NAMEOF_TYPE_RAW_T(decltype(structvar)) == "SomeStruct"); - REQUIRE(NAMEOF_TYPE_RAW_T(decltype(ptrvar)) == "SomeStruct *"); - REQUIRE(NAMEOF_TYPE_RAW_T(decltype(refvar)) == "SomeStruct &"); - REQUIRE(NAMEOF_TYPE_RAW_T(SomeStruct) == "SomeStruct"); - REQUIRE(NAMEOF_TYPE_RAW_T(SomeStruct *) == "SomeStruct *"); - REQUIRE(NAMEOF_TYPE_RAW_T(SomeStruct &) == "SomeStruct &"); - REQUIRE(NAMEOF_TYPE_RAW_T(const SomeStruct volatile *) == "const volatile SomeStruct *"); + REQUIRE(NAMEOF_TYPE_T(decltype(structvar)) == "SomeStruct"); + REQUIRE(NAMEOF_TYPE_T(decltype(ptrvar)) == "SomeStruct *"); + REQUIRE(NAMEOF_TYPE_T(decltype(refvar)) == "SomeStruct &"); + REQUIRE(NAMEOF_TYPE_T(SomeStruct) == "SomeStruct"); + REQUIRE(NAMEOF_TYPE_T(SomeStruct *) == "SomeStruct *"); + REQUIRE(NAMEOF_TYPE_T(SomeStruct &) == "SomeStruct &"); + REQUIRE(NAMEOF_TYPE_T(const SomeStruct volatile *) == "const volatile SomeStruct *"); - REQUIRE(NAMEOF_TYPE_RAW_T(SomeClass) == "SomeClass"); - REQUIRE(NAMEOF_TYPE_RAW_T(const SomeClass volatile *) == "const volatile SomeClass *"); + REQUIRE(NAMEOF_TYPE_T(SomeClass) == "SomeClass"); + REQUIRE(NAMEOF_TYPE_T(const SomeClass volatile *) == "const volatile SomeClass *"); - REQUIRE(NAMEOF_TYPE_RAW_T(decltype(othervar)) == "Long"); - REQUIRE(NAMEOF_TYPE_RAW_T(Long) == "Long"); - REQUIRE(NAMEOF_TYPE_RAW_T(Long::LL) == "Long::LL"); + REQUIRE(NAMEOF_TYPE_T(decltype(othervar)) == "Long"); + REQUIRE(NAMEOF_TYPE_T(Long) == "Long"); + REQUIRE(NAMEOF_TYPE_T(Long::LL) == "Long::LL"); - REQUIRE(NAMEOF_TYPE_RAW_T(Color) == "Color"); + REQUIRE(NAMEOF_TYPE_T(Color) == "Color"); #elif defined(_MSC_VER) - REQUIRE(NAMEOF_TYPE_RAW_T(decltype(structvar)) == "SomeStruct"); - REQUIRE(NAMEOF_TYPE_RAW_T(decltype(ptrvar)) == "SomeStruct *"); - REQUIRE(NAMEOF_TYPE_RAW_T(decltype(refvar)) == "SomeStruct &"); - REQUIRE(NAMEOF_TYPE_RAW_T(SomeStruct) == "SomeStruct"); - REQUIRE(NAMEOF_TYPE_RAW_T(SomeStruct *) == "SomeStruct *"); - REQUIRE(NAMEOF_TYPE_RAW_T(SomeStruct &) == "SomeStruct &"); - REQUIRE(NAMEOF_TYPE_RAW_T(const SomeStruct volatile *) == "SomeStruct const volatile *"); + REQUIRE(NAMEOF_TYPE_T(decltype(structvar)) == "SomeStruct"); + REQUIRE(NAMEOF_TYPE_T(decltype(ptrvar)) == "SomeStruct *"); + REQUIRE(NAMEOF_TYPE_T(decltype(refvar)) == "SomeStruct &"); + REQUIRE(NAMEOF_TYPE_T(SomeStruct) == "SomeStruct"); + REQUIRE(NAMEOF_TYPE_T(SomeStruct *) == "SomeStruct *"); + REQUIRE(NAMEOF_TYPE_T(SomeStruct &) == "SomeStruct &"); + REQUIRE(NAMEOF_TYPE_T(const SomeStruct volatile *) == "SomeStruct const volatile *"); - REQUIRE(NAMEOF_TYPE_RAW_T(SomeClass) == "SomeClass"); - REQUIRE(NAMEOF_TYPE_RAW_T(const SomeClass volatile *) == "SomeClass const volatile *"); + REQUIRE(NAMEOF_TYPE_T(SomeClass) == "SomeClass"); + REQUIRE(NAMEOF_TYPE_T(const SomeClass volatile *) == "SomeClass const volatile *"); - REQUIRE(NAMEOF_TYPE_RAW_T(decltype(othervar)) == "Long"); - REQUIRE(NAMEOF_TYPE_RAW_T(Long) == "Long"); - REQUIRE(NAMEOF_TYPE_RAW_T(Long::LL) == "Long::LL"); + REQUIRE(NAMEOF_TYPE_T(decltype(othervar)) == "Long"); + REQUIRE(NAMEOF_TYPE_T(Long) == "Long"); + REQUIRE(NAMEOF_TYPE_T(Long::LL) == "Long::LL"); - REQUIRE(NAMEOF_TYPE_RAW_T(Color) == "Color"); + REQUIRE(NAMEOF_TYPE_T(Color) == "Color"); #elif defined(__GNUC__) - REQUIRE(NAMEOF_TYPE_RAW_T(decltype(structvar)) == "SomeStruct"); - REQUIRE(NAMEOF_TYPE_RAW_T(decltype(ptrvar)) == "SomeStruct*"); - REQUIRE(NAMEOF_TYPE_RAW_T(decltype(refvar)) == "SomeStruct&"); - REQUIRE(NAMEOF_TYPE_RAW_T(SomeStruct) == "SomeStruct"); - REQUIRE(NAMEOF_TYPE_RAW_T(SomeStruct *) == "SomeStruct*"); - REQUIRE(NAMEOF_TYPE_RAW_T(SomeStruct &) == "SomeStruct&"); - REQUIRE(NAMEOF_TYPE_RAW_T(const SomeStruct volatile *) == "const volatile SomeStruct*"); + REQUIRE(NAMEOF_TYPE_T(decltype(structvar)) == "SomeStruct"); + REQUIRE(NAMEOF_TYPE_T(decltype(ptrvar)) == "SomeStruct*"); + REQUIRE(NAMEOF_TYPE_T(decltype(refvar)) == "SomeStruct&"); + REQUIRE(NAMEOF_TYPE_T(SomeStruct) == "SomeStruct"); + REQUIRE(NAMEOF_TYPE_T(SomeStruct *) == "SomeStruct*"); + REQUIRE(NAMEOF_TYPE_T(SomeStruct &) == "SomeStruct&"); + REQUIRE(NAMEOF_TYPE_T(const SomeStruct volatile *) == "const volatile SomeStruct*"); - REQUIRE(NAMEOF_TYPE_RAW_T(SomeClass) == "SomeClass"); - REQUIRE(NAMEOF_TYPE_RAW_T(const SomeClass volatile *) == "const volatile SomeClass*"); + REQUIRE(NAMEOF_TYPE_T(SomeClass) == "SomeClass"); + REQUIRE(NAMEOF_TYPE_T(const SomeClass volatile *) == "const volatile SomeClass*"); - REQUIRE(NAMEOF_TYPE_RAW_T(decltype(othervar)) == "Long"); - REQUIRE(NAMEOF_TYPE_RAW_T(Long) == "Long"); - REQUIRE(NAMEOF_TYPE_RAW_T(Long::LL) == "Long::LL"); + REQUIRE(NAMEOF_TYPE_T(decltype(othervar)) == "Long"); + REQUIRE(NAMEOF_TYPE_T(Long) == "Long"); + REQUIRE(NAMEOF_TYPE_T(Long::LL) == "Long::LL"); - REQUIRE(NAMEOF_TYPE_RAW_T(Color) == "Color"); + REQUIRE(NAMEOF_TYPE_T(Color) == "Color"); #endif } @@ -454,10 +362,6 @@ TEST_CASE("Spaces and Tabs ignored") { REQUIRE(NAMEOF_TYPE( structvar ) == "SomeStruct"); REQUIRE(NAMEOF_TYPE_T( decltype(structvar) ) == "SomeStruct"); - REQUIRE(NAMEOF_TYPE_FULL( structvar ) == "SomeStruct"); - REQUIRE(NAMEOF_TYPE_FULL_T( decltype(structvar) ) == "SomeStruct"); - REQUIRE(NAMEOF_TYPE_RAW( structvar ) == "SomeStruct"); - REQUIRE(NAMEOF_TYPE_RAW_T( decltype(structvar) ) == "SomeStruct"); } SECTION("Tabs") { @@ -467,9 +371,5 @@ TEST_CASE("Spaces and Tabs ignored") { REQUIRE(NAMEOF_TYPE( structvar ) == "SomeStruct"); REQUIRE(NAMEOF_TYPE_T( decltype(structvar) ) == "SomeStruct"); - REQUIRE(NAMEOF_TYPE_FULL( structvar ) == "SomeStruct"); - REQUIRE(NAMEOF_TYPE_FULL_T( decltype(structvar) ) == "SomeStruct"); - REQUIRE(NAMEOF_TYPE_RAW( structvar ) == "SomeStruct"); - REQUIRE(NAMEOF_TYPE_RAW_T( decltype(structvar) ) == "SomeStruct"); } }