diff --git a/entity/name-of.hpp b/entity/name-of.hpp index 42674a19..01688fe4 100644 --- a/entity/name-of.hpp +++ b/entity/name-of.hpp @@ -1,4 +1,5 @@ #pragma once +#include "compat/assert.hpp" #include #if defined _MSC_VER @@ -7,9 +8,9 @@ #define FM_PRETTY_FUNCTION __PRETTY_FUNCTION__ #endif -template -static constexpr auto mangled_name() { // NOLINT(bugprone-reserved-identifier) +template static constexpr auto mangled_name() { using namespace Corrade::Containers; + using Corrade::Containers::Literals::operator ""_s; using SVF = StringViewFlag; constexpr auto my_strlen = [](const char* str) constexpr -> size_t { const char* start = str; @@ -17,8 +18,28 @@ static constexpr auto mangled_name() { // NOLINT(bugprone-reserved-identifier) ; return (size_t)(str - start); }; - const char* str = FM_PRETTY_FUNCTION; - return StringView { str, my_strlen(str), SVF::Global|SVF::NullTerminated }; + const char* str_ = FM_PRETTY_FUNCTION; + auto str = StringView { str_, my_strlen(str_), SVF::Global|SVF::NullTerminated }; +#if 1 + { +#ifdef _MSC_VER + constexpr StringView prefix = "auto __cdecl mangled_name<"_s, suffix = ">(void)"_s; +#elif defined __clang__ + constexpr StringView prefix = "auto mangled_name() [T = "_s, suffix = "]"_s; +#else + constexpr StringView prefix = "constexpr auto mangled_name() [with T = "_s, suffix = "]"_s; +#endif + + fm_assert(str.size() > prefix.size() + suffix.size()); + for (auto i = 0uz; i < prefix.size(); i++) + fm_assert(str[i] == prefix[i]); + str = StringView{ str.data() + prefix.size(), str.size() - prefix.size() }; + for (auto i = 0uz; i < suffix.size(); i++) + fm_assert(str[str.size() - 1 - i] == suffix[suffix.size() - 1 - i]); + str = StringView{ str.data(), str.size() - suffix.size() }; + } +#endif + return str; } template constexpr inline auto name_of = mangled_name();