@@ -33,35 +33,47 @@ enum GTestParamIndex : uint8_t { kTaskGetter, kNameTest, kTestParams };
3333std::string GetAbsolutePath (const std::string &relative_path);
3434int GetNumThreads ();
3535
36- #if (defined(__clang__) || defined(__GNUC__)) && !defined(_MSC_VER)
3736template <typename T>
38- consteval std::string_view GetNamespace () {
37+ constexpr std::string_view GetNamespace () {
38+ #if defined(__clang__) || defined(__GNUC__)
3939 constexpr std::string_view kFunc = __PRETTY_FUNCTION__;
40- // example: "consteval std::string_view get_namespace() [with T = my_namespace::MyClass]"
4140 constexpr std::string_view kKey = " T = " ;
41+
42+ auto start = kFunc .find (kKey );
43+ if (start == std::string_view::npos) return {};
44+ start += kKey .size ();
45+
46+ auto end = kFunc .rfind (" ::" );
47+ if (end == std::string_view::npos || end <= start) return {};
48+
49+ return kFunc .substr (start, end - start);
50+
4251#elif defined(_MSC_VER)
43- template <typename T>
44- constexpr std::string_view GetNamespace () {
4552 constexpr std::string_view kFunc = __FUNCSIG__;
46- // example: "class std::basic_string_view<char,struct std::char_traits<char> > __cdecl get_namespace<class
47- // my_namespace::MyClass>(void)"
48- constexpr std::string_view kKey = " get_namespace<" ;
49- #else
50- static_assert (false , " Unsupported compiler" );
51- #endif
53+ constexpr std::string_view kKey = " GetNamespace<" ;
5254
5355 auto start = kFunc .find (kKey );
54- if (start == std::string_view::npos) {
55- return {};
56- }
56+ if (start == std::string_view::npos) return {};
5757 start += kKey .size ();
5858
59- auto end = kFunc .find (" ::" , start);
60- if (end == std::string_view::npos) {
61- return {};
59+ // Удалим class/struct/enum/union префиксы
60+ constexpr std::string_view prefixes[] = {" class " , " struct " , " enum " , " union " };
61+ for (auto prefix : prefixes) {
62+ if (kFunc .substr (start, prefix.size ()) == prefix) {
63+ start += prefix.size ();
64+ break ;
65+ }
6266 }
6367
68+ auto end = kFunc .rfind (" ::" );
69+ if (end == std::string_view::npos || end <= start) return {};
70+
6471 return kFunc .substr (start, end - start);
72+
73+ #else
74+ static_assert ([] { return false ; }(), " Unsupported compiler" );
75+ return {};
76+ #endif
6577}
6678
6779bool IsUnderMpirun ();
0 commit comments