fix: text stripping in type_name fixed

This commit is contained in:
Mateusz Pusz
2025-04-29 11:35:10 +02:00
parent 110a56dc30
commit f9acaa8879

View File

@ -6,6 +6,7 @@
#pragma once
#ifndef MP_UNITS_IN_MODULE_INTERFACE
#include <mp-units/ext/contracts.h>
#ifdef MP_UNITS_IMPORT_STD
import std;
#else
@ -22,17 +23,19 @@ template<typename T>
std::string_view name, prefix, suffix;
#ifdef __clang__
name = __PRETTY_FUNCTION__;
prefix = "auto type_name() [T = ";
prefix = "std::string_view mp_units::detail::type_name() [T = ";
suffix = "]";
#elif defined(__GNUC__)
name = __PRETTY_FUNCTION__;
prefix = "constexpr auto type_name() [with T = ";
prefix = "consteval std::string_view mp_units::detail::type_name() [with T = ";
suffix = "]";
#elif defined(_MSC_VER)
name = __FUNCSIG__;
prefix = "auto __cdecl type_name<";
prefix = "class std::basic_string_view<char,struct std::char_traits<char> > __cdecl mp_units::detail::type_name<";
suffix = ">(void)";
#endif
MP_UNITS_ASSERT_DEBUG(name.starts_with(prefix));
MP_UNITS_ASSERT_DEBUG(name.ends_with(suffix));
name.remove_prefix(prefix.size());
name.remove_suffix(suffix.size());
return name;