Add static_variant::operator==
For real this time :)
This commit is contained in:
parent
94cb1858b8
commit
292584ca59
2 changed files with 10 additions and 5 deletions
|
|
@ -221,6 +221,14 @@ public:
|
||||||
return *this;
|
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>>
|
template<typename X, typename = type_in_typelist<X>>
|
||||||
X& get() {
|
X& get() {
|
||||||
if(_tag == typelist::index_of<list, X>()) {
|
if(_tag == typelist::index_of<list, X>()) {
|
||||||
|
|
|
||||||
|
|
@ -182,10 +182,7 @@ BOOST_AUTO_TEST_CASE( nested_objects_test )
|
||||||
|
|
||||||
from_variant( v, sv1, nested_levels + 2 );
|
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) {
|
BOOST_CHECK( sv == sv1 );
|
||||||
return v1.get<fc::test::item>() == v2.get<fc::test::item>();
|
|
||||||
};
|
|
||||||
BOOST_CHECK( sv_equal(sv, sv1) );
|
|
||||||
|
|
||||||
// both log and dump should never throw
|
// both log and dump should never throw
|
||||||
BOOST_TEST_MESSAGE( "========== About to log static_variant. ==========" );
|
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 );
|
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
|
// both log and dump should never throw
|
||||||
BOOST_TEST_MESSAGE( "========== About to log vector. ==========" );
|
BOOST_TEST_MESSAGE( "========== About to log vector. ==========" );
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue