nameof_enum supported on the GCC >= 9
This commit is contained in:
parent
af53b6eadb
commit
223b9e606c
2 changed files with 2 additions and 45 deletions
|
@ -165,12 +165,8 @@ template <typename E, E V>
|
||||||
#if defined(__clang__)
|
#if defined(__clang__)
|
||||||
std::string_view name{__PRETTY_FUNCTION__};
|
std::string_view name{__PRETTY_FUNCTION__};
|
||||||
constexpr auto suffix = sizeof("]") - 1;
|
constexpr auto suffix = sizeof("]") - 1;
|
||||||
#elif defined(__GNUC__)
|
#elif defined(__GNUC__) && __GNUC__ >= 9
|
||||||
std::string_view name{__PRETTY_FUNCTION__};
|
std::string_view name{__PRETTY_FUNCTION__};
|
||||||
# if __GNUC__ < 9
|
|
||||||
constexpr auto prefix = sizeof("constexpr std::string_view nameof::detail::nameof_enum_impl() [with E = ") + nameof_type_impl<identity<E>>().length() + sizeof("; V = ");
|
|
||||||
name.remove_prefix(prefix);
|
|
||||||
# endif
|
|
||||||
constexpr auto suffix = sizeof("; std::string_view = std::basic_string_view<char>]") - 1;
|
constexpr auto suffix = sizeof("; std::string_view = std::basic_string_view<char>]") - 1;
|
||||||
#elif defined(_MSC_VER)
|
#elif defined(_MSC_VER)
|
||||||
std::string_view name{__FUNCSIG__};
|
std::string_view name{__FUNCSIG__};
|
||||||
|
@ -179,16 +175,14 @@ template <typename E, E V>
|
||||||
return "nameof_enum::unsupported_compiler";
|
return "nameof_enum::unsupported_compiler";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__clang__) || defined(__GNUC__) || defined(_MSC_VER)
|
#if defined(__clang__) || (defined(__GNUC__) && __GNUC__ >= 9) || defined(_MSC_VER)
|
||||||
name.remove_suffix(suffix);
|
name.remove_suffix(suffix);
|
||||||
# if defined(__clang__) || (defined(__GNUC__) && __GNUC__ >= 9) || defined(_MSC_VER)
|
|
||||||
for (std::size_t i = name.size(); i > 0; --i) {
|
for (std::size_t i = name.size(); i > 0; --i) {
|
||||||
if (!is_name_char(name[i - 1])) {
|
if (!is_name_char(name[i - 1])) {
|
||||||
name.remove_prefix(i);
|
name.remove_prefix(i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
# endif
|
|
||||||
return name;
|
return name;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -223,17 +223,6 @@ TEST_CASE("NAMEOF_ENUM") {
|
||||||
|
|
||||||
REQUIRE(NAMEOF_ENUM(Directions::Right) == "Right");
|
REQUIRE(NAMEOF_ENUM(Directions::Right) == "Right");
|
||||||
REQUIRE(NAMEOF_ENUM(directions) == "Right");
|
REQUIRE(NAMEOF_ENUM(directions) == "Right");
|
||||||
#elif defined(__GNUC__)
|
|
||||||
REQUIRE(NAMEOF_ENUM(Color::RED) == "(Color)-1");
|
|
||||||
REQUIRE(NAMEOF_ENUM(color) == "(Color)-1");
|
|
||||||
|
|
||||||
REQUIRE(NAMEOF_ENUM(Color::BLUE) == "(Color)1");
|
|
||||||
REQUIRE(NAMEOF_ENUM(color_) == "(Color)1");
|
|
||||||
|
|
||||||
REQUIRE(NAMEOF_ENUM(m[1]) == "(Color)0");
|
|
||||||
|
|
||||||
REQUIRE(NAMEOF_ENUM(Directions::Right) == "(Directions)2");
|
|
||||||
REQUIRE(NAMEOF_ENUM(directions) == "(Directions)2");
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -251,17 +240,6 @@ TEST_CASE("nameof::nameof_enum<T>(value)") {
|
||||||
|
|
||||||
REQUIRE(nameof::nameof_enum(Directions::Right) == "Right");
|
REQUIRE(nameof::nameof_enum(Directions::Right) == "Right");
|
||||||
REQUIRE(nameof::nameof_enum(directions) == "Right");
|
REQUIRE(nameof::nameof_enum(directions) == "Right");
|
||||||
#elif defined(__GNUC__)
|
|
||||||
REQUIRE(nameof::nameof_enum(Color::RED) == "(Color)-1");
|
|
||||||
REQUIRE(nameof::nameof_enum(color) == "(Color)-1");
|
|
||||||
|
|
||||||
REQUIRE(nameof::nameof_enum(Color::BLUE) == "(Color)1");
|
|
||||||
REQUIRE(nameof::nameof_enum(color_) == "(Color)1");
|
|
||||||
|
|
||||||
REQUIRE(nameof::nameof_enum(m[1]) == "(Color)0");
|
|
||||||
|
|
||||||
REQUIRE(nameof::nameof_enum(Directions::Right) == "(Directions)2");
|
|
||||||
REQUIRE(nameof::nameof_enum(directions) == "(Directions)2");
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,17 +257,6 @@ TEST_CASE("nameof::nameof_enum<value>()") {
|
||||||
|
|
||||||
REQUIRE(nameof::nameof_enum<Directions::Right>() == "Right");
|
REQUIRE(nameof::nameof_enum<Directions::Right>() == "Right");
|
||||||
REQUIRE(nameof::nameof_enum<directions>() == "Right");
|
REQUIRE(nameof::nameof_enum<directions>() == "Right");
|
||||||
#elif defined(__GNUC__)
|
|
||||||
REQUIRE(nameof::nameof_enum<Color::RED>() == "(Color)-1");
|
|
||||||
REQUIRE(nameof::nameof_enum<color>() == "(Color)-1");
|
|
||||||
|
|
||||||
REQUIRE(nameof::nameof_enum<Color::BLUE>() == "(Color)1");
|
|
||||||
REQUIRE(nameof::nameof_enum<color_>() == "(Color)1");
|
|
||||||
|
|
||||||
REQUIRE(nameof::nameof_enum<m[1]>() == "(Color)0");
|
|
||||||
|
|
||||||
REQUIRE(nameof::nameof_enum<Directions::Right>() == "(Directions)2");
|
|
||||||
REQUIRE(nameof::nameof_enum<directions>() == "(Directions)2");
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -456,8 +423,6 @@ TEST_CASE("Spaces and Tabs ignored") {
|
||||||
REQUIRE(NAMEOF_RAW( struct_var ) == "struct_var");
|
REQUIRE(NAMEOF_RAW( struct_var ) == "struct_var");
|
||||||
#if defined(__clang__) || (defined(__GNUC__) && __GNUC__ >= 9) || defined(_MSC_VER)
|
#if defined(__clang__) || (defined(__GNUC__) && __GNUC__ >= 9) || defined(_MSC_VER)
|
||||||
REQUIRE(NAMEOF_ENUM( color ) == "RED");
|
REQUIRE(NAMEOF_ENUM( color ) == "RED");
|
||||||
#elif defined(__GNUC__)
|
|
||||||
REQUIRE(NAMEOF_ENUM( color ) == "(Color)-1");
|
|
||||||
#endif
|
#endif
|
||||||
REQUIRE(NAMEOF_TYPE( struct_var ) == "SomeStruct");
|
REQUIRE(NAMEOF_TYPE( struct_var ) == "SomeStruct");
|
||||||
REQUIRE(NAMEOF_TYPE_T( decltype(struct_var) ) == "SomeStruct");
|
REQUIRE(NAMEOF_TYPE_T( decltype(struct_var) ) == "SomeStruct");
|
||||||
|
@ -469,8 +434,6 @@ TEST_CASE("Spaces and Tabs ignored") {
|
||||||
REQUIRE(NAMEOF_RAW( struct_var ) == "struct_var");
|
REQUIRE(NAMEOF_RAW( struct_var ) == "struct_var");
|
||||||
#if defined(__clang__) || (defined(__GNUC__) && __GNUC__ >= 9) || defined(_MSC_VER)
|
#if defined(__clang__) || (defined(__GNUC__) && __GNUC__ >= 9) || defined(_MSC_VER)
|
||||||
REQUIRE(NAMEOF_ENUM( color ) == "RED");
|
REQUIRE(NAMEOF_ENUM( color ) == "RED");
|
||||||
#elif defined(__GNUC__)
|
|
||||||
REQUIRE(NAMEOF_ENUM( color ) == "(Color)-1");
|
|
||||||
#endif
|
#endif
|
||||||
REQUIRE(NAMEOF_TYPE( struct_var ) == "SomeStruct");
|
REQUIRE(NAMEOF_TYPE( struct_var ) == "SomeStruct");
|
||||||
REQUIRE(NAMEOF_TYPE_T( decltype(struct_var) ) == "SomeStruct");
|
REQUIRE(NAMEOF_TYPE_T( decltype(struct_var) ) == "SomeStruct");
|
||||||
|
|
Loading…
Reference in a new issue