@@ -23,38 +23,27 @@ namespace cib::detail {
2323 }
2424 };
2525
26- // clang-8 and below don't have constexpr find_first_of on std::string_view
27- CIB_CONSTEVAL std::string_view::size_type find_first_of (std::string_view str, char c) {
28- using size_type = std::string_view::size_type;
29- for (size_type i = 0 ; i < str.size (); i++) {
30- if (str[i] == c) {
31- return i;
32- }
33- }
34-
35- return 0 ;
36- }
37-
38- // clang-8 and below don't have constexpr find_last_of on std::string_view
39- CIB_CONSTEVAL std::string_view::size_type find_last_of (std::string_view str, char c) {
40- using size_type = std::string_view::size_type;
41- size_type match = str.size ();
42- for (size_type i = 0 ; i < str.size (); i++) {
43- if (str[i] == c) {
44- match = i;
45- }
46- }
47-
48- return match;
49- }
50-
5126 template <typename Tag>
52- CIB_CONSTEVAL static std::string_view name () {
53- constexpr std::string_view function_name = __PRETTY_FUNCTION__;
54- constexpr auto lhs = find_first_of (function_name, ' <' );
55- constexpr auto rhs = find_last_of (function_name, ' >' );
56- constexpr auto service_name = function_name.substr (lhs, rhs - lhs);
57- return service_name;
27+ constexpr static std::string_view name () {
28+ #if defined(__clang__)
29+ constexpr std::string_view function_name = __PRETTY_FUNCTION__;
30+ constexpr auto lhs = 44 ;
31+ constexpr auto rhs = function_name.size () - 2 ;
32+
33+ #elif defined(__GNUC__) || defined(__GNUG__)
34+ constexpr std::string_view function_name = __PRETTY_FUNCTION__;
35+ constexpr auto lhs = 59 ;
36+ constexpr auto rhs = function_name.size () - 51 ;
37+
38+ #elif #elif defined(_MSC_VER)
39+ constexpr std::string_view function_name = __FUNCSIG__;
40+ constexpr auto lhs = 0 ;
41+ constexpr auto rhs = function_name.size ();
42+ #else
43+ static_assert (false , " Unknown compiler, can't build type name." );
44+ #endif
45+
46+ return function_name.substr (lhs, rhs - lhs + 1 );
5847 }
5948
6049
0 commit comments