#pragma once #include #include #include #include namespace ovdl::detail { template constexpr auto substring_as_array(std::string_view str, std::index_sequence) { return std::array { str[Idxs]... }; } template constexpr auto type_name_array() { #if defined(__clang__) constexpr auto prefix = std::string_view { "[T = " }; constexpr auto suffix = std::string_view { "]" }; constexpr auto function = std::string_view { __PRETTY_FUNCTION__ }; #elif defined(__GNUC__) constexpr auto prefix = std::string_view { "with T = " }; constexpr auto suffix = std::string_view { "]" }; constexpr auto function = std::string_view { __PRETTY_FUNCTION__ }; #elif defined(_MSC_VER) constexpr auto prefix = std::string_view { "type_name_array<" }; constexpr auto suffix = std::string_view { ">(void)" }; constexpr auto function = std::string_view { __FUNCSIG__ }; #else #error Unsupported compiler #endif constexpr auto start = function.find(prefix) + prefix.size(); constexpr auto end = function.rfind(suffix); static_assert(start < end); constexpr auto name = function.substr(start, (end - start)); return substring_as_array(name, std::make_index_sequence {}); } template struct type_name_holder { static inline constexpr auto value = type_name_array(); }; template constexpr auto type_name() -> std::string_view { constexpr auto& value = type_name_holder::value; return std::string_view { value.data(), value.size() }; } }