Skip to content

Commit 02c37f5

Browse files
committed
[reflection] compatibility of type_string with '*'
1 parent 978503e commit 02c37f5

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

include/ylt/reflection/template_string.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ inline constexpr auto type_string() {
4242
constexpr refvalue::meta_string name{
4343
std::span<const char, str.size()>{str.data(), str.size()}};
4444
#if defined(__clang__)
45-
constexpr auto name_no_blank = refvalue::replace_v<name, " &", "&">;
46-
return name_no_blank;
45+
constexpr auto name_ref = refvalue::replace_v<name, " &", "&">;
46+
constexpr auto name_pointer = refvalue::replace_v<name_ref, " *", "*">;
47+
return name_pointer;
4748
#elif defined(_MSC_VER)
4849
constexpr auto name_no_struct = refvalue::remove_v<name, "struct ">;
4950
constexpr auto name_no_class = refvalue::remove_v<name_no_struct, "class ">;

src/reflection/tests/test_reflection.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,26 +481,42 @@ TEST_CASE("test type_string") {
481481
CHECK(type_string<volatile int>() == "volatile int");
482482
CHECK(type_string<int&>() == "int&");
483483
CHECK(type_string<int&&>() == "int&&");
484+
CHECK(type_string<int*>() == "int*");
484485
CHECK(type_string<const int&>() == "const int&");
485486
CHECK(type_string<const int&&>() == "const int&&");
487+
CHECK(type_string<const int*>() == "const int*");
486488
CHECK(type_string<test_type_string::struct_test>() == "test_type_string::struct_test");
487489
CHECK(type_string<test_type_string::struct_test&>() == "test_type_string::struct_test&");
488490
CHECK(type_string<test_type_string::struct_test&&>() == "test_type_string::struct_test&&");
491+
CHECK(type_string<test_type_string::struct_test*>() == "test_type_string::struct_test*");
489492
CHECK(type_string<const test_type_string::struct_test>() == "const test_type_string::struct_test");
490493
CHECK(type_string<const test_type_string::struct_test&>() == "const test_type_string::struct_test&");
491494
CHECK(type_string<const test_type_string::struct_test&&>() == "const test_type_string::struct_test&&");
495+
CHECK(type_string<const test_type_string::struct_test*>() == "const test_type_string::struct_test*");
492496
CHECK(type_string<test_type_string::class_test>() == "test_type_string::class_test");
493497
CHECK(type_string<test_type_string::class_test&>() == "test_type_string::class_test&");
494498
CHECK(type_string<test_type_string::class_test&&>() == "test_type_string::class_test&&");
499+
CHECK(type_string<test_type_string::class_test*>() == "test_type_string::class_test*");
495500
CHECK(type_string<const test_type_string::class_test>() == "const test_type_string::class_test");
496501
CHECK(type_string<const test_type_string::class_test&>() == "const test_type_string::class_test&");
497502
CHECK(type_string<const test_type_string::class_test&&>() == "const test_type_string::class_test&&");
503+
CHECK(type_string<const test_type_string::class_test*>() == "const test_type_string::class_test*");
498504
CHECK(type_string<test_type_string::union_test>() == "test_type_string::union_test");
499505
CHECK(type_string<test_type_string::union_test&>() == "test_type_string::union_test&");
500506
CHECK(type_string<test_type_string::union_test&&>() == "test_type_string::union_test&&");
507+
CHECK(type_string<test_type_string::union_test*>() == "test_type_string::union_test*");
501508
CHECK(type_string<const test_type_string::union_test>() == "const test_type_string::union_test");
502509
CHECK(type_string<const test_type_string::union_test&>() == "const test_type_string::union_test&");
503510
CHECK(type_string<const test_type_string::union_test&&>() == "const test_type_string::union_test&&");
511+
CHECK(type_string<const test_type_string::union_test*>() == "const test_type_string::union_test*");
512+
CHECK(type_string<std::string>() == "std::basic_string<char>");
513+
CHECK(type_string<std::string&>() == "std::basic_string<char>&");
514+
CHECK(type_string<std::string&&>() == "std::basic_string<char>&&");
515+
CHECK(type_string<std::string*>() == "std::basic_string<char>*");
516+
CHECK(type_string<const std::string>() == "const std::basic_string<char>");
517+
CHECK(type_string<const std::string&>() == "const std::basic_string<char>&");
518+
CHECK(type_string<const std::string&&>() == "const std::basic_string<char>&&");
519+
CHECK(type_string<const std::string*>() == "const std::basic_string<char>*");
504520
}
505521

506522
DOCTEST_MSVC_SUPPRESS_WARNING_WITH_PUSH(4007)

0 commit comments

Comments
 (0)