json/tree: correct object and array equality operators
This commit is contained in:
parent
94640d00f0
commit
3d51be1372
@ -11,7 +11,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Copyright 2010-2015 Danny Robson <danny@nerdcruft.net>
|
||||
* Copyright 2010-2018 Danny Robson <danny@nerdcruft.net>
|
||||
*/
|
||||
|
||||
|
||||
@ -22,6 +22,7 @@
|
||||
|
||||
#include "../debug.hpp"
|
||||
#include "../io.hpp"
|
||||
#include "../iterator.hpp"
|
||||
#include "../maths.hpp"
|
||||
#include "../stream.hpp"
|
||||
|
||||
@ -520,15 +521,16 @@ json::tree::object::clone (void) const
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
bool
|
||||
json::tree::object::operator ==(const json::tree::object &rhs) const
|
||||
json::tree::object::operator== (const json::tree::object &rhs) const
|
||||
{
|
||||
for (auto i = rhs.m_values.begin (), j = m_values.begin ();
|
||||
i != rhs.m_values.end () && j != m_values.end ();
|
||||
++i, ++j)
|
||||
{
|
||||
if (i->first != j->first)
|
||||
if (rhs.size () != size ())
|
||||
return false;
|
||||
if ((*i->second) != (*j->second))
|
||||
|
||||
for (auto const &[i,j]: util::zip (m_values, rhs.m_values)) {
|
||||
if (i.first != j.first)
|
||||
return false;
|
||||
|
||||
if (*i.second != *j.second)
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -679,10 +681,12 @@ json::tree::array::insert (std::unique_ptr<json::tree::node> &&_value)
|
||||
bool
|
||||
json::tree::array::operator==(const json::tree::array &rhs) const
|
||||
{
|
||||
for (auto i = rhs.m_values.begin (), j = m_values.begin ();
|
||||
i != rhs.m_values.end () && j != m_values.end ();
|
||||
++i, ++j)
|
||||
{ if ((**i) != (**j)) return false; }
|
||||
if (rhs.size () != size ())
|
||||
return false;
|
||||
|
||||
for (auto const &[i,j]: util::zip (m_values, rhs.m_values))
|
||||
if (*i != *j)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -11,7 +11,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Copyright 2010-2015 Danny Robson <danny@nerdcruft.net>
|
||||
* Copyright 2010-2018 Danny Robson <danny@nerdcruft.net>
|
||||
*/
|
||||
|
||||
#ifndef __UTIL_JSON_TREE_HPP
|
||||
|
Loading…
Reference in New Issue
Block a user