json/tree: correct object and array equality operators

This commit is contained in:
Danny Robson 2018-07-05 17:46:02 +10:00
parent 94640d00f0
commit 3d51be1372
2 changed files with 17 additions and 13 deletions

View File

@ -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"
@ -522,13 +523,14 @@ json::tree::object::clone (void) const
bool
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;
}

View File

@ -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