From 7b1c8c9682ffa7c7fa0a3b94e282414908607229 Mon Sep 17 00:00:00 2001 From: "ryosuke.hirakida" Date: Fri, 13 Dec 2024 19:40:49 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Make=20`type=5Fname`=20available=20?= =?UTF-8?q?with=20MSVC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/field_reflection.hpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/include/field_reflection.hpp b/include/field_reflection.hpp index 6ed06dc..44edbcc 100644 --- a/include/field_reflection.hpp +++ b/include/field_reflection.hpp @@ -664,6 +664,7 @@ namespace field_reflection template consteval std::string_view get_type_name() { +#if defined(__GNUC__) || defined(__clang__) constexpr auto detector_name = get_function_name(); constexpr auto dummy = std::string_view("T = "); constexpr auto dummy_begin = detector_name.find(dummy) + dummy.size(); @@ -672,6 +673,25 @@ namespace field_reflection constexpr auto type_name_raw = get_function_name(); return type_name_raw.substr(dummy_begin, type_name_raw.size() - dummy_begin - dummy_suffix_length); +#else + constexpr auto detector_name = get_function_name(); + constexpr auto dummy = std::string_view("struct field_reflection::detail::field_name_detector"); + constexpr auto dummy_begin = detector_name.find(dummy); + constexpr auto dummy_suffix_length = detector_name.size() - dummy_begin - dummy.size(); + + auto field_name_raw = get_function_name(); + auto field_name = + field_name_raw.substr(dummy_begin, field_name_raw.size() - dummy_begin - dummy_suffix_length); + if (auto s = std::string_view("struct "); field_name.starts_with(s)) + { + field_name.remove_prefix(s.size()); + } + if (auto s = std::string_view("class "); field_name.starts_with(s)) + { + field_name.remove_prefix(s.size()); + } + return field_name; +#endif } template