Skip to content

Commit

Permalink
fixed iterator comparisons
Browse files Browse the repository at this point in the history
  • Loading branch information
nlohmann committed Feb 21, 2015
1 parent 12b29f5 commit 2890d69
Show file tree
Hide file tree
Showing 3 changed files with 1,074 additions and 918 deletions.
22 changes: 12 additions & 10 deletions src/json.hpp
Expand Up @@ -2128,9 +2128,10 @@ class basic_json
/// comparison: equal
inline bool operator==(const iterator& other) const
{
if (m_object != other.m_object or m_object->m_type != other.m_object->m_type)
// if objects are not the same, the comparison is undefined
if (m_object != other.m_object)
{
return false;
throw std::domain_error("cannot compare iterators of different containers");
}

switch (m_object->m_type)
Expand Down Expand Up @@ -2161,10 +2162,10 @@ class basic_json
/// comparison: smaller
inline bool operator<(const iterator& other) const
{
// if types are different, use them to compare iterators
if (m_object->m_type != other.m_object->m_type)
// if objects are not the same, the comparison is undefined
if (m_object != other.m_object)
{
return (m_object->m_type < other.m_object->m_type);
throw std::domain_error("cannot compare iterators of different containers");
}

switch (m_object->m_type)
Expand Down Expand Up @@ -2625,9 +2626,10 @@ class basic_json
/// comparison: equal
inline bool operator==(const const_iterator& other) const
{
if (m_object != other.m_object or m_object->m_type != other.m_object->m_type)
// if objects are not the same, the comparison is undefined
if (m_object != other.m_object)
{
return false;
throw std::domain_error("cannot compare iterators of different containers");
}

switch (m_object->m_type)
Expand Down Expand Up @@ -2658,10 +2660,10 @@ class basic_json
/// comparison: smaller
inline bool operator<(const const_iterator& other) const
{
// if types are different, use them to compare iterators
if (m_object->m_type != other.m_object->m_type)
// if objects are not the same, the comparison is undefined
if (m_object != other.m_object)
{
return (m_object->m_type < other.m_object->m_type);
throw std::domain_error("cannot compare iterators of different containers");
}

switch (m_object->m_type)
Expand Down
22 changes: 12 additions & 10 deletions src/json.hpp.re2c
Expand Up @@ -2128,9 +2128,10 @@ class basic_json
/// comparison: equal
inline bool operator==(const iterator& other) const
{
if (m_object != other.m_object or m_object->m_type != other.m_object->m_type)
// if objects are not the same, the comparison is undefined
if (m_object != other.m_object)
{
return false;
throw std::domain_error("cannot compare iterators of different containers");
}

switch (m_object->m_type)
Expand Down Expand Up @@ -2161,10 +2162,10 @@ class basic_json
/// comparison: smaller
inline bool operator<(const iterator& other) const
{
// if types are different, use them to compare iterators
if (m_object->m_type != other.m_object->m_type)
// if objects are not the same, the comparison is undefined
if (m_object != other.m_object)
{
return (m_object->m_type < other.m_object->m_type);
throw std::domain_error("cannot compare iterators of different containers");
}

switch (m_object->m_type)
Expand Down Expand Up @@ -2625,9 +2626,10 @@ class basic_json
/// comparison: equal
inline bool operator==(const const_iterator& other) const
{
if (m_object != other.m_object or m_object->m_type != other.m_object->m_type)
// if objects are not the same, the comparison is undefined
if (m_object != other.m_object)
{
return false;
throw std::domain_error("cannot compare iterators of different containers");
}

switch (m_object->m_type)
Expand Down Expand Up @@ -2658,10 +2660,10 @@ class basic_json
/// comparison: smaller
inline bool operator<(const const_iterator& other) const
{
// if types are different, use them to compare iterators
if (m_object->m_type != other.m_object->m_type)
// if objects are not the same, the comparison is undefined
if (m_object != other.m_object)
{
return (m_object->m_type < other.m_object->m_type);
throw std::domain_error("cannot compare iterators of different containers");
}

switch (m_object->m_type)
Expand Down

0 comments on commit 2890d69

Please sign in to comment.