diff --git a/include/fc/reflect/typename.hpp b/include/fc/reflect/typename.hpp index 3fe9a83..41fc348 100644 --- a/include/fc/reflect/typename.hpp +++ b/include/fc/reflect/typename.hpp @@ -12,6 +12,7 @@ #include namespace fc { + template class static_variant; class value; class exception; namespace ip { class address; } @@ -41,10 +42,19 @@ namespace fc { return n.c_str(); } }; - template struct get_typename> + template struct get_typename> + { + static const char* name() { + static std::string n = std::string("flat_set<") + get_typename::name() + ">"; + return n.c_str(); + } + }; + template + struct get_typename, typename static_variant::type_lt>> { static const char* name() { - static std::string n = std::string("flat_set<") + get_typename::name() + ">"; + using TN = get_typename>; + static std::string n = std::string("flat_set<") + TN::name() + ", " + TN::name() + "::type_lt>"; return n.c_str(); } }; diff --git a/include/fc/static_variant.hpp b/include/fc/static_variant.hpp index 6f1841c..89baa4e 100644 --- a/include/fc/static_variant.hpp +++ b/include/fc/static_variant.hpp @@ -302,6 +302,14 @@ public: static constexpr int value = impl::position::pos; }; + struct type_lt { + bool operator()(const static_variant& a, const static_variant& b) const { return a.which() < b.which(); } + }; + struct type_eq { + bool operator()(const static_variant& a, const static_variant& b) const { return a.which() == b.which(); } + }; + using flat_set_type = flat_set; + static_variant() { init_from_tag(0); @@ -352,14 +360,6 @@ public: v.visit( impl::move_construct(*this) ); return *this; } - friend bool operator == ( const static_variant& a, const static_variant& b ) - { - return a.which() == b.which(); - } - friend bool operator < ( const static_variant& a, const static_variant& b ) - { - return a.which() < b.which(); - } template> X& get() { diff --git a/tests/variant_test.cpp b/tests/variant_test.cpp index 96e62b5..474e5ae 100644 --- a/tests/variant_test.cpp +++ b/tests/variant_test.cpp @@ -182,7 +182,10 @@ BOOST_AUTO_TEST_CASE( nested_objects_test ) from_variant( v, sv1, nested_levels + 2 ); - BOOST_CHECK( sv == sv1 ); + auto sv_equal = [](const fc::static_variant& v1, const fc::static_variant& v2) { + return v1.get() == v2.get(); + }; + BOOST_CHECK( sv_equal(sv, sv1) ); // both log and dump should never throw BOOST_TEST_MESSAGE( "========== About to log static_variant. ==========" ); @@ -215,7 +218,7 @@ BOOST_AUTO_TEST_CASE( nested_objects_test ) from_variant( v, vec1, nested_levels + 3 ); - BOOST_CHECK( vec == vec1 ); + BOOST_CHECK( std::equal(vec.begin(), vec.end(), vec1.begin(), sv_equal) ); // both log and dump should never throw BOOST_TEST_MESSAGE( "========== About to log vector. ==========" );