Skip to content

Commit

Permalink
Add static_variant::operator==
Browse files Browse the repository at this point in the history
For real this time :)
  • Loading branch information
nathanielhourt committed Aug 30, 2019
1 parent 4a09fb1 commit b306bd5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 8 additions & 0 deletions include/fc/static_variant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,14 @@ class static_variant {
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<typename decltype(t)::type>() == b.get<typename decltype(t)::type>();
});
}

template<typename X, typename = type_in_typelist<X>>
X& get() {
if(_tag == typelist::index_of<list, X>()) {
Expand Down
7 changes: 2 additions & 5 deletions tests/variant_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<fc::test::item>& v1, const fc::static_variant<fc::test::item>& v2) {
return v1.get<fc::test::item>() == v2.get<fc::test::item>();
};
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. ==========" );
Expand Down Expand Up @@ -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. ==========" );
Expand Down

0 comments on commit b306bd5

Please sign in to comment.