diff --git a/iguana/ylt/reflection/template_string.hpp b/iguana/ylt/reflection/template_string.hpp index 46a5cb0d..5a04cda8 100644 --- a/iguana/ylt/reflection/template_string.hpp +++ b/iguana/ylt/reflection/template_string.hpp @@ -31,18 +31,21 @@ constexpr std::string_view get_raw_name() { template inline constexpr std::string_view type_string() { constexpr std::string_view sample = get_raw_name(); - constexpr size_t pos = sample.find("int"); + constexpr size_t prefix_length = sample.find("int"); constexpr std::string_view str = get_raw_name(); - constexpr auto next1 = str.rfind(sample[pos + 3]); + constexpr size_t suffix_length = sample.size() - prefix_length - 3; + constexpr auto name = + str.substr(prefix_length, str.size() - prefix_length - suffix_length); #if defined(_MSC_VER) - constexpr std::size_t npos = str.find_first_of(" ", pos); - if (npos != std::string_view::npos) - return str.substr(npos + 1, next1 - npos - 1); - else - return str.substr(pos, next1 - pos); -#else - return str.substr(pos, next1 - pos); + constexpr size_t space_pos = name.find(" "); + if constexpr (space_pos != std::string_view::npos) { + constexpr auto prefix = name.substr(0, space_pos); + if constexpr (prefix != "const" && prefix != "volatile") { + return name.substr(space_pos + 1); + } + } #endif + return name; } template diff --git a/test/test_reflection.cpp b/test/test_reflection.cpp index 0253be70..4e47f2b5 100644 --- a/test/test_reflection.cpp +++ b/test/test_reflection.cpp @@ -557,15 +557,15 @@ TEST_CASE("test type_string") { #endif #if defined(_MSC_VER) && !defined(__clang__) CHECK(type_string() == - "struct test_type_string::struct_test"); + "test_type_string::struct_test"); CHECK(type_string() == "const struct test_type_string::struct_test"); CHECK(type_string() == - "class test_type_string::class_test"); + "test_type_string::class_test"); CHECK(type_string() == "const class test_type_string::class_test"); CHECK(type_string() == - "union test_type_string::union_test"); + "test_type_string::union_test"); CHECK(type_string() == "const union test_type_string::union_test"); #else