1#ifndef LIBSBX_UTILITY_TYPE_NAME_HPP_
2#define LIBSBX_UTILITY_TYPE_NAME_HPP_
6#include <libsbx/utility/target.hpp>
8namespace sbx::utility {
12constexpr auto parse_type_name(std::string_view prefix, std::string_view suffix, std::string_view function) -> std::string_view {
13 const auto start = function.find(prefix) + prefix.size();
14 const auto end = function.find(suffix);
15 const auto size = end - start;
17 return function.substr(start, size);
22template<
typename Type>
23constexpr auto type_name() -> std::string_view {
25 constexpr auto prefix = std::string_view{
"[Type = "};
26 constexpr auto suffix =
"]";
27 constexpr auto function = std::string_view{__PRETTY_FUNCTION__};
29 return detail::parse_type_name(prefix, suffix, function);
30#elif (defined(__GNUC__) || defined(__GNUG__) || defined(__MINGW32__))
31 constexpr auto prefix = std::string_view{
"with Type = "};
32 constexpr auto suffix =
"; ";
33 constexpr auto function = std::string_view{__PRETTY_FUNCTION__};
35 return detail::parse_type_name(prefix, suffix, function);
36#elif defined(__MSC_VER)
37 constexpr auto prefix = std::string_view{
"type_name<"};
38 constexpr auto suffix =
">(void)";
39 constexpr auto function = std::string_view{__FUNCSIG__};
41 return detail::parse_type_name(prefix, suffix, function);
43 return typeid(Type).name();