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
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* 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 "../debug.hpp"
|
||||||
#include "../io.hpp"
|
#include "../io.hpp"
|
||||||
|
#include "../iterator.hpp"
|
||||||
#include "../maths.hpp"
|
#include "../maths.hpp"
|
||||||
#include "../stream.hpp"
|
#include "../stream.hpp"
|
||||||
|
|
||||||
@ -522,13 +523,14 @@ json::tree::object::clone (void) const
|
|||||||
bool
|
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 ();
|
if (rhs.size () != size ())
|
||||||
i != rhs.m_values.end () && j != m_values.end ();
|
|
||||||
++i, ++j)
|
|
||||||
{
|
|
||||||
if (i->first != j->first)
|
|
||||||
return false;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -679,10 +681,12 @@ json::tree::array::insert (std::unique_ptr<json::tree::node> &&_value)
|
|||||||
bool
|
bool
|
||||||
json::tree::array::operator==(const json::tree::array &rhs) const
|
json::tree::array::operator==(const json::tree::array &rhs) const
|
||||||
{
|
{
|
||||||
for (auto i = rhs.m_values.begin (), j = m_values.begin ();
|
if (rhs.size () != size ())
|
||||||
i != rhs.m_values.end () && j != m_values.end ();
|
return false;
|
||||||
++i, ++j)
|
|
||||||
{ if ((**i) != (**j)) return false; }
|
for (auto const &[i,j]: util::zip (m_values, rhs.m_values))
|
||||||
|
if (*i != *j)
|
||||||
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* 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
|
#ifndef __UTIL_JSON_TREE_HPP
|
||||||
|
Loading…
Reference in New Issue
Block a user