Skip to content

Commit

Permalink
[reflection] compatibility of type_string with '*'
Browse files Browse the repository at this point in the history
  • Loading branch information
miyanyan committed Jan 5, 2025
1 parent 978503e commit 02c37f5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 3 additions & 2 deletions include/ylt/reflection/template_string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ inline constexpr auto type_string() {
constexpr refvalue::meta_string name{
std::span<const char, str.size()>{str.data(), str.size()}};
#if defined(__clang__)
constexpr auto name_no_blank = refvalue::replace_v<name, " &", "&">;
return name_no_blank;
constexpr auto name_ref = refvalue::replace_v<name, " &", "&">;
constexpr auto name_pointer = refvalue::replace_v<name_ref, " *", "*">;
return name_pointer;
#elif defined(_MSC_VER)
constexpr auto name_no_struct = refvalue::remove_v<name, "struct ">;
constexpr auto name_no_class = refvalue::remove_v<name_no_struct, "class ">;
Expand Down
16 changes: 16 additions & 0 deletions src/reflection/tests/test_reflection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,26 +481,42 @@ TEST_CASE("test type_string") {
CHECK(type_string<volatile int>() == "volatile int");
CHECK(type_string<int&>() == "int&");
CHECK(type_string<int&&>() == "int&&");
CHECK(type_string<int*>() == "int*");
CHECK(type_string<const int&>() == "const int&");
CHECK(type_string<const int&&>() == "const int&&");
CHECK(type_string<const int*>() == "const int*");
CHECK(type_string<test_type_string::struct_test>() == "test_type_string::struct_test");
CHECK(type_string<test_type_string::struct_test&>() == "test_type_string::struct_test&");
CHECK(type_string<test_type_string::struct_test&&>() == "test_type_string::struct_test&&");
CHECK(type_string<test_type_string::struct_test*>() == "test_type_string::struct_test*");
CHECK(type_string<const test_type_string::struct_test>() == "const test_type_string::struct_test");
CHECK(type_string<const test_type_string::struct_test&>() == "const test_type_string::struct_test&");
CHECK(type_string<const test_type_string::struct_test&&>() == "const test_type_string::struct_test&&");
CHECK(type_string<const test_type_string::struct_test*>() == "const test_type_string::struct_test*");
CHECK(type_string<test_type_string::class_test>() == "test_type_string::class_test");
CHECK(type_string<test_type_string::class_test&>() == "test_type_string::class_test&");
CHECK(type_string<test_type_string::class_test&&>() == "test_type_string::class_test&&");
CHECK(type_string<test_type_string::class_test*>() == "test_type_string::class_test*");
CHECK(type_string<const test_type_string::class_test>() == "const test_type_string::class_test");
CHECK(type_string<const test_type_string::class_test&>() == "const test_type_string::class_test&");
CHECK(type_string<const test_type_string::class_test&&>() == "const test_type_string::class_test&&");
CHECK(type_string<const test_type_string::class_test*>() == "const test_type_string::class_test*");
CHECK(type_string<test_type_string::union_test>() == "test_type_string::union_test");
CHECK(type_string<test_type_string::union_test&>() == "test_type_string::union_test&");
CHECK(type_string<test_type_string::union_test&&>() == "test_type_string::union_test&&");
CHECK(type_string<test_type_string::union_test*>() == "test_type_string::union_test*");
CHECK(type_string<const test_type_string::union_test>() == "const test_type_string::union_test");
CHECK(type_string<const test_type_string::union_test&>() == "const test_type_string::union_test&");
CHECK(type_string<const test_type_string::union_test&&>() == "const test_type_string::union_test&&");
CHECK(type_string<const test_type_string::union_test*>() == "const test_type_string::union_test*");
CHECK(type_string<std::string>() == "std::basic_string<char>");
CHECK(type_string<std::string&>() == "std::basic_string<char>&");
CHECK(type_string<std::string&&>() == "std::basic_string<char>&&");
CHECK(type_string<std::string*>() == "std::basic_string<char>*");
CHECK(type_string<const std::string>() == "const std::basic_string<char>");
CHECK(type_string<const std::string&>() == "const std::basic_string<char>&");
CHECK(type_string<const std::string&&>() == "const std::basic_string<char>&&");
CHECK(type_string<const std::string*>() == "const std::basic_string<char>*");
}

DOCTEST_MSVC_SUPPRESS_WARNING_WITH_PUSH(4007)
Expand Down

0 comments on commit 02c37f5

Please sign in to comment.