diff --git a/include/fc/static_variant.hpp b/include/fc/static_variant.hpp index 757ebb3..5c3695f 100644 --- a/include/fc/static_variant.hpp +++ b/include/fc/static_variant.hpp @@ -221,6 +221,14 @@ public: return *this; } + friend bool operator==( const static_variant& a, const static_variant& b ) { + if (a.which() != b.which()) + return false; + return typelist::runtime::dispatch(list(), a.which(), [&a, &b](auto t) { + return a.get() == b.get(); + }); + } + template> X& get() { if(_tag == typelist::index_of()) { diff --git a/tests/variant_test.cpp b/tests/variant_test.cpp index 474e5ae..96e62b5 100644 --- a/tests/variant_test.cpp +++ b/tests/variant_test.cpp @@ -182,10 +182,7 @@ BOOST_AUTO_TEST_CASE( nested_objects_test ) from_variant( v, sv1, nested_levels + 2 ); - auto sv_equal = [](const fc::static_variant& v1, const fc::static_variant& v2) { - return v1.get() == v2.get(); - }; - BOOST_CHECK( sv_equal(sv, sv1) ); + BOOST_CHECK( sv == sv1 ); // both log and dump should never throw BOOST_TEST_MESSAGE( "========== About to log static_variant. ==========" ); @@ -218,7 +215,7 @@ BOOST_AUTO_TEST_CASE( nested_objects_test ) from_variant( v, vec1, nested_levels + 3 ); - BOOST_CHECK( std::equal(vec.begin(), vec.end(), vec1.begin(), sv_equal) ); + BOOST_CHECK( vec == vec1 ); // both log and dump should never throw BOOST_TEST_MESSAGE( "========== About to log vector. ==========" );