Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions include/fc/variant_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ namespace fc
variant_object& operator=( mutable_variant_object&& );
variant_object& operator=( const mutable_variant_object& );

friend bool operator ==( const variant_object& obj1, const variant_object& obj2 );
friend bool operator !=( const variant_object& obj1, const variant_object& obj2 ) {
return !( obj1 == obj2 );
}

private:
std::shared_ptr< std::vector< entry > > _key_value;
friend class mutable_variant_object;
Expand Down
1 change: 1 addition & 0 deletions src/variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,7 @@ string format_string( const string& format, const variant_object& args )
if( a.is_int64() || b.is_int64() ) return a.as_int64() == b.as_int64();
if( a.is_uint64() || b.is_uint64() ) return a.as_uint64() == b.as_uint64();
if( a.is_array() || b.is_array() ) return a.get_array() == b.get_array();
if( a.is_object() || b.is_object() ) return a.get_object() == b.get_object();
return false;
}

Expand Down
15 changes: 15 additions & 0 deletions src/variant_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,21 @@ namespace fc
}


bool operator ==( const variant_object& obj1, const variant_object& obj2 ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the order which these iterators traverse a (mutable_)?variant_object is not strictly defined as ordered. As a result this comparison will return false when comparing these two objects:

auto lhs = mutable_variant_object()("foo", 1)("bar", 1);
auto rhs = mutable_variant_object()("bar", 1)("foo", 1);

// expect are_equal to be true but it is not!
bool are_equal = (lhs == rhs); 

auto it1 = obj1.begin();
auto it2 = obj2.begin();
for ( ; it1 != obj1.end() && it2 != obj2.end(); ++it1, ++it2 ) {
if ( *it1 != *it2 )
return false;
}

if ( it1 != obj1.end() || it2 != obj2.end() )
return false;

return true;
}


void to_variant( const variant_object& var, variant& vo )
{
vo = variant(var);
Expand Down