wip NAMEOF_TYPE_RTTI
This commit is contained in:
parent
2cdcdc0f83
commit
7bf624de33
2 changed files with 22 additions and 2 deletions
|
@ -60,6 +60,11 @@
|
||||||
# define NAMEOF_TYPE_SUPPORTED 1
|
# define NAMEOF_TYPE_SUPPORTED 1
|
||||||
#endif
|
#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.
|
// Checks nameof_enum compiler compatibility.
|
||||||
#if defined(__clang__) || defined(__GNUC__) && __GNUC__ >= 9 || defined(_MSC_VER)
|
#if defined(__clang__) || defined(__GNUC__) && __GNUC__ >= 9 || defined(_MSC_VER)
|
||||||
# undef NAMEOF_ENUM_SUPPORTED
|
# undef NAMEOF_ENUM_SUPPORTED
|
||||||
|
@ -672,10 +677,10 @@ template <typename T>
|
||||||
#define NAMEOF_FULL_TYPE_EXPR(...) ::nameof::nameof_full_type<decltype(__VA_ARGS__)>()
|
#define NAMEOF_FULL_TYPE_EXPR(...) ::nameof::nameof_full_type<decltype(__VA_ARGS__)>()
|
||||||
|
|
||||||
// Obtains string name of type using RTTI.
|
// 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())
|
# define NAMEOF_TYPE_RTTI(...) ::nameof::detail::n(typeid(__VA_ARGS__).name())
|
||||||
#else
|
#else
|
||||||
# define NAMEOF_TYPE_RTTI(...)
|
# define NAMEOF_TYPE_RTTI(...) static_assert(sizeof(__VA_ARGS__) < 0, "NAMEOF_TYPE_RTTI unsupported compiler.");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
|
|
|
@ -684,3 +684,18 @@ TEST_CASE("nameof::nameof_type") {
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#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
|
||||||
|
|
Loading…
Reference in a new issue