diff --git a/include/bits/soi-dbg.hpp b/include/bits/soi-dbg.hpp index 7bc3da9..dc5e2e1 100644 --- a/include/bits/soi-dbg.hpp +++ b/include/bits/soi-dbg.hpp @@ -90,16 +90,6 @@ public: } }; -struct static_string_no_std { - bool is_debug; - bool is_std; - static_string type; - CONSTEXPR11_TN static_string_no_std(bool is_debug, - bool is_std, - static_string type) - : is_debug(is_debug), is_std(is_std), type(type) {} -}; - inline std::ostream& operator<<(std::ostream& os, static_string const& s) @@ -107,20 +97,6 @@ operator<<(std::ostream& os, static_string const& s) return os.write(s.data(), s.size()); } -inline -std::ostream& -operator<<(std::ostream& os, static_string_no_std const& s) { - if (s.is_debug) { - const int k = sizeof("std::__debug::") - 1; - return os.write(s.type.data()+k, s.type.size()-k); - } else if (s.is_std) { - const int k = sizeof("std::") - 1; - return os.write(s.type.data()+k, s.type.size()-k); - } else { - return os.write(s.type.data(), s.type.size()); - } -} - template CONSTEXPR14_TN static_string @@ -143,29 +119,25 @@ type_name() #endif } +constexpr bool is_prefix_of(char const *suffix, char const *s) { + return suffix[0]=='\0' || (suffix[0] == s[0] && is_prefix_of(suffix + 1, s + 1)); +} + +static char const* const type_string = "string"; + template CONSTEXPR14_TN -static_string_no_std +static_string sanitized_type_name() { CONSTEXPR14_TN static_string t = type_name(); - CONSTEXPR14_TN bool is_std = - t.size() >= sizeof("std::") && - t[ 0] == 's' && - t[ 1] == 't' && - t[ 2] == 'd' && - t[ 3] == ':' && - t[ 4] == ':'; - CONSTEXPR14_TN bool is_debug = - is_std && - t.size() >= sizeof("std::__debug::") && - t[ 5] == '_' && - t[ 6] == '_' && - t[ 7] == 'd' && - t[ 8] == 'e' && - t[ 9] == 'b' && - t[10] == 'u' && - t[11] == 'g'; - return static_string_no_std(is_debug, is_std, t); + CONSTEXPR14_TN std::size_t offset = + is_prefix_of("std::__debug::", t.data()) ? sizeof("std::__debug::")-1 : + is_prefix_of("std::", t.data()) ? sizeof("std::")-1 : + 0; + return + is_prefix_of("std::__cxx11::basic_string", t.data()) ? + static_string(type_string, sizeof(type_string)-2) : + static_string(t.data()+offset, t.size()-offset); } // ---------------------------------------------------------------------------- @@ -236,7 +208,7 @@ void dbg_init() { template T&& dbg_print(T&& value, - static_string_no_std const& type, + static_string const& type, char const* file, int line, char const* function_name, @@ -259,7 +231,7 @@ T&& dbg_print(T&& value, template auto dbg_print(const char (&msg)[N], - static_string_no_std const&, + static_string const&, char const* file, int line, char const* function_name,