From c92f1d0b33c6ce8b5ff88d99f320f24e9b98d344 Mon Sep 17 00:00:00 2001 From: Patrick Urbanke Date: Sun, 3 Dec 2023 17:38:25 +0100 Subject: [PATCH] get_struct_name for MSVC --- include/rfl/internal/get_struct_name.hpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/include/rfl/internal/get_struct_name.hpp b/include/rfl/internal/get_struct_name.hpp index 603ecec2..2b457163 100644 --- a/include/rfl/internal/get_struct_name.hpp +++ b/include/rfl/internal/get_struct_name.hpp @@ -16,10 +16,21 @@ inline std::string remove_namespaces(const std::string& _name) { return _name.substr(pos + 1); } +inline size_t find_begin(const std::string& _func_name) { + const size_t pos1 = _func_name.find("T = "); + if (pos1 != std::string::npos) { + // clang and gcc + return pos1 + 4; + } + // MSVC + const size_t pos2 = _func_name.find_last_of(" "); + return (pos2 != std::string::npos) ? pos2 + 1 : pos2; +} + template std::string get_struct_name_impl() { const std::string func_name = std::source_location::current().function_name(); - const size_t begin = func_name.find("T = ") + 4; + const size_t begin = find_begin(func_name); if (begin == std::string::npos) { return "AnonymousStruct"; }