wip NAMEOF_TYPE_RTTI

This commit is contained in:
neargye 2020-06-03 19:33:01 +05:00
parent 2cdcdc0f83
commit 7bf624de33
2 changed files with 22 additions and 2 deletions

View file

@ -60,6 +60,11 @@
# define NAMEOF_TYPE_SUPPORTED 1
#endif
#if defined(__cpp_rtti) || defined(_CPPRTTI) || defined(__GXX_RTTI)
# undef NAMEOF_TYPE_RTTI_SUPPORTED
# define NAMEOF_TYPE_RTTI_SUPPORTED 1
#endif
// Checks nameof_enum compiler compatibility.
#if defined(__clang__) || defined(__GNUC__) && __GNUC__ >= 9 || defined(_MSC_VER)
# undef NAMEOF_ENUM_SUPPORTED
@ -672,10 +677,10 @@ template <typename T>
#define NAMEOF_FULL_TYPE_EXPR(...) ::nameof::nameof_full_type<decltype(__VA_ARGS__)>()
// Obtains string name of type using RTTI.
#if defined(__cpp_rtti) || defined(_CPPRTTI) || defined(__GXX_RTTI)
#if defined(NAMEOF_TYPE_RTTI_SUPPORTED) && NAMEOF_TYPE_RTTI_SUPPORTED
# define NAMEOF_TYPE_RTTI(...) ::nameof::detail::n(typeid(__VA_ARGS__).name())
#else
# define NAMEOF_TYPE_RTTI(...)
# define NAMEOF_TYPE_RTTI(...) static_assert(sizeof(__VA_ARGS__) < 0, "NAMEOF_TYPE_RTTI unsupported compiler.");
#endif
#if defined(_MSC_VER)

View file

@ -684,3 +684,18 @@ TEST_CASE("nameof::nameof_type") {
}
#endif
#if defined(NAMEOF_TYPE_RTTI_SUPPORTED) && NAMEOF_TYPE_RTTI_SUPPORTED
TEST_CASE("NAMEOF_TYPE_RTTI") {
#if defined(__clang__)
REQUIRE(NAMEOF_TYPE_RTTI(std::string) == "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >");
REQUIRE(NAMEOF_TYPE_RTTI(Color) == "Color");
#elif defined(_MSC_VER)
REQUIRE(NAMEOF_TYPE_RTTI(std::string) == "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >");
REQUIRE(NAMEOF_TYPE_RTTI(Color) == "enum Color");
#elif defined(__GNUC__)
REQUIRE(NAMEOF_TYPE_RTTI(std::string) == "std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >");
REQUIRE(NAMEOF_TYPE_RTTI(Color) == "Color");
#endif
}
#endif