From 48901cd1a43949c64fcfbdddc1e774147d8d74ad Mon Sep 17 00:00:00 2001 From: John Jones Date: Fri, 10 Aug 2018 14:40:47 -0500 Subject: [PATCH 1/4] correct templating of static variant --- include/fc/static_variant.hpp | 43 ++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/include/fc/static_variant.hpp b/include/fc/static_variant.hpp index 02fb5dc..88efeda 100644 --- a/include/fc/static_variant.hpp +++ b/include/fc/static_variant.hpp @@ -382,5 +382,46 @@ public: s.visit( to_static_variant(ar[1], max_depth - 1) ); } - template struct get_typename { static const char* name() { return typeid(static_variant).name(); } }; + template< typename... T > struct get_comma_separated_typenames; + + template<> + struct get_comma_separated_typenames<> + { + static const char* names() { return ""; } + }; + + template< typename T > + struct get_comma_separated_typenames + { + static const char* names() + { + static const std::string n = get_typename::name(); + return n.c_str(); + } + }; + + template< typename T, typename... Ts > + struct get_comma_separated_typenames + { + static const char* names() + { + static const std::string n = + std::string( get_typename::name() )+","+ + std::string( get_comma_separated_typenames< Ts... >::names() ); + return n.c_str(); + } + }; + + template< typename... T > + struct get_typename< static_variant< T... > > + { + static const char* name() + { + static const std::string n = std::string( "fc::static_variant<" ) + + get_comma_separated_typenames::names() + + ">"; + return n.c_str(); + } + }; + } // namespace fc From da33edc384db1da6c31ff1c28c04c1aca442278d Mon Sep 17 00:00:00 2001 From: John Jones Date: Fri, 10 Aug 2018 15:33:25 -0500 Subject: [PATCH 2/4] additional typenames --- include/fc/reflect/typename.hpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/include/fc/reflect/typename.hpp b/include/fc/reflect/typename.hpp index 5cd55c9..5777f34 100644 --- a/include/fc/reflect/typename.hpp +++ b/include/fc/reflect/typename.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -69,6 +70,22 @@ namespace fc { return n.c_str(); } }; + template struct get_typename< std::set > + { + static const char* name() + { + static std::string n = std::string("std::set<") + std::string(get_typename::name()) + std::string(">"); + return n.c_str(); + } + }; + template struct get_typename< std::pair > + { + static const char* name() + { + static std::string n = std::string("std::pair<") + get_typename::name() + "," + get_typename::name() + ">"; + return n.c_str(); + } + }; struct signed_int; struct unsigned_int; From e8961888752c7203d67cd64c7a712b30e35dd21b Mon Sep 17 00:00:00 2001 From: John Jones Date: Fri, 10 Aug 2018 20:40:21 -0500 Subject: [PATCH 3/4] additional templates for get_typename --- include/fc/reflect/typename.hpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/fc/reflect/typename.hpp b/include/fc/reflect/typename.hpp index 5777f34..c5bba19 100644 --- a/include/fc/reflect/typename.hpp +++ b/include/fc/reflect/typename.hpp @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -86,10 +87,19 @@ namespace fc { return n.c_str(); } }; + template struct get_typename< fc::smart_ref > + { + static const char* name() + { + return (std::string("fc::smart_ref<") + get_typename::name() + std::string(">")).c_str(); + } + }; struct signed_int; struct unsigned_int; + struct variant_object; template<> struct get_typename { static const char* name() { return "signed_int"; } }; template<> struct get_typename { static const char* name() { return "unsigned_int"; } }; + template<> struct get_typename { static const char* name() { return "fc::variant_object"; } }; } From 9ba8886c8bb36905d4fbdcc38ebfcd67beb9915e Mon Sep 17 00:00:00 2001 From: John Jones Date: Sun, 12 Aug 2018 19:57:43 -0500 Subject: [PATCH 4/4] Change string to static --- include/fc/reflect/typename.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/fc/reflect/typename.hpp b/include/fc/reflect/typename.hpp index c5bba19..55695c2 100644 --- a/include/fc/reflect/typename.hpp +++ b/include/fc/reflect/typename.hpp @@ -91,7 +91,8 @@ namespace fc { { static const char* name() { - return (std::string("fc::smart_ref<") + get_typename::name() + std::string(">")).c_str(); + static std::string n = std::string("fc::smart_ref<") + get_typename::name() + std::string(">"); + return n.c_str(); } };