2#ifndef LIBSBX_UTILITY_TYPE_NAME_HPP_
3#define LIBSBX_UTILITY_TYPE_NAME_HPP_
7#include <libsbx/utility/target.hpp>
9namespace sbx::utility {
13constexpr auto parse_type_name(std::string_view prefix, std::string_view suffix, std::string_view function) -> std::string_view {
14 const auto start = function.find(prefix) + prefix.size();
15 const auto end = function.find(suffix);
16 const auto size = end - start;
18 return function.substr(start, size);
23template<
typename Type>
24constexpr auto type_name() -> std::string_view {
26 constexpr auto prefix = std::string_view{
"[Type = "};
27 constexpr auto suffix =
"]";
28 constexpr auto function = std::string_view{__PRETTY_FUNCTION__};
30 return detail::parse_type_name(prefix, suffix, function);
31#elif (defined(__GNUC__) || defined(__GNUG__) || defined(__MINGW32__))
32 constexpr auto prefix = std::string_view{
"with Type = "};
33 constexpr auto suffix =
"; ";
34 constexpr auto function = std::string_view{__PRETTY_FUNCTION__};
36 return detail::parse_type_name(prefix, suffix, function);
37#elif defined(__MSC_VER)
38 constexpr auto prefix = std::string_view{
"type_name<"};
39 constexpr auto suffix =
">(void)";
40 constexpr auto function = std::string_view{__FUNCSIG__};
42 return detail::parse_type_name(prefix, suffix, function);
44 return typeid(Type).name();