mirror of
https://github.com/nlohmann/json
synced 2024-11-27 14:20:07 +00:00
fix typos and improve operator==
This commit is contained in:
parent
28f64c22a9
commit
306695dd25
68
src/json.hpp
68
src/json.hpp
@ -1868,74 +1868,52 @@ class basic_json
|
||||
*/
|
||||
friend bool operator==(const_reference lhs, const_reference rhs) noexcept
|
||||
{
|
||||
switch (lhs.type())
|
||||
const auto lhs_type = lhs.type();
|
||||
const auto rhs_type = rhs.type();
|
||||
if (lhs_type == rhs_type)
|
||||
{
|
||||
case (value_t::array):
|
||||
switch (lhs_type)
|
||||
{
|
||||
if (rhs.type() == value_t::array)
|
||||
case (value_t::array):
|
||||
{
|
||||
return *lhs.m_value.array == *rhs.m_value.array;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case (value_t::object):
|
||||
{
|
||||
if (rhs.type() == value_t::object)
|
||||
case (value_t::object):
|
||||
{
|
||||
return *lhs.m_value.object == *rhs.m_value.object;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case (value_t::null):
|
||||
{
|
||||
if (rhs.type() == value_t::null)
|
||||
case (value_t::null):
|
||||
{
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case (value_t::string):
|
||||
{
|
||||
if (rhs.type() == value_t::string)
|
||||
case (value_t::string):
|
||||
{
|
||||
return *lhs.m_value.string == *rhs.m_value.string;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case (value_t::boolean):
|
||||
{
|
||||
if (rhs.type() == value_t::boolean)
|
||||
case (value_t::boolean):
|
||||
{
|
||||
return lhs.m_value.boolean == rhs.m_value.boolean;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case (value_t::number_integer):
|
||||
{
|
||||
if (rhs.type() == value_t::number_integer)
|
||||
case (value_t::number_integer):
|
||||
{
|
||||
return lhs.m_value.number_integer == rhs.m_value.number_integer;
|
||||
}
|
||||
if (rhs.type() == value_t::number_float)
|
||||
{
|
||||
return lhs.m_value.number_integer == static_cast<number_integer_t>(rhs.m_value.number_float);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case (value_t::number_float):
|
||||
{
|
||||
if (rhs.type() == value_t::number_integer)
|
||||
{
|
||||
return approx(lhs.m_value.number_float, static_cast<number_float_t>(rhs.m_value.number_integer));
|
||||
}
|
||||
if (rhs.type() == value_t::number_float)
|
||||
case (value_t::number_float):
|
||||
{
|
||||
return approx(lhs.m_value.number_float, rhs.m_value.number_float);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_float)
|
||||
{
|
||||
return lhs.m_value.number_integer ==
|
||||
static_cast<number_integer_t>(rhs.m_value.number_float);
|
||||
}
|
||||
else if (lhs_type == value_t::number_float and rhs_type == value_t::number_integer)
|
||||
{
|
||||
return approx(lhs.m_value.number_float,
|
||||
static_cast<number_float_t>(rhs.m_value.number_integer));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1959,9 +1937,9 @@ class basic_json
|
||||
{
|
||||
case (value_t::array):
|
||||
{
|
||||
return *lhs.m_value_array < *rhs.m_value.array;
|
||||
return *lhs.m_value.array < *rhs.m_value.array;
|
||||
}
|
||||
case (value_t::onject):
|
||||
case (value_t::object):
|
||||
{
|
||||
return *lhs.m_value.object < *rhs.m_value.object;
|
||||
}
|
||||
|
@ -1868,74 +1868,52 @@ class basic_json
|
||||
*/
|
||||
friend bool operator==(const_reference lhs, const_reference rhs) noexcept
|
||||
{
|
||||
switch (lhs.type())
|
||||
const auto lhs_type = lhs.type();
|
||||
const auto rhs_type = rhs.type();
|
||||
if (lhs_type == rhs_type)
|
||||
{
|
||||
case (value_t::array):
|
||||
switch (lhs_type)
|
||||
{
|
||||
if (rhs.type() == value_t::array)
|
||||
case (value_t::array):
|
||||
{
|
||||
return *lhs.m_value.array == *rhs.m_value.array;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case (value_t::object):
|
||||
{
|
||||
if (rhs.type() == value_t::object)
|
||||
case (value_t::object):
|
||||
{
|
||||
return *lhs.m_value.object == *rhs.m_value.object;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case (value_t::null):
|
||||
{
|
||||
if (rhs.type() == value_t::null)
|
||||
case (value_t::null):
|
||||
{
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case (value_t::string):
|
||||
{
|
||||
if (rhs.type() == value_t::string)
|
||||
case (value_t::string):
|
||||
{
|
||||
return *lhs.m_value.string == *rhs.m_value.string;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case (value_t::boolean):
|
||||
{
|
||||
if (rhs.type() == value_t::boolean)
|
||||
case (value_t::boolean):
|
||||
{
|
||||
return lhs.m_value.boolean == rhs.m_value.boolean;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case (value_t::number_integer):
|
||||
{
|
||||
if (rhs.type() == value_t::number_integer)
|
||||
case (value_t::number_integer):
|
||||
{
|
||||
return lhs.m_value.number_integer == rhs.m_value.number_integer;
|
||||
}
|
||||
if (rhs.type() == value_t::number_float)
|
||||
{
|
||||
return lhs.m_value.number_integer == static_cast<number_integer_t>(rhs.m_value.number_float);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case (value_t::number_float):
|
||||
{
|
||||
if (rhs.type() == value_t::number_integer)
|
||||
{
|
||||
return approx(lhs.m_value.number_float, static_cast<number_float_t>(rhs.m_value.number_integer));
|
||||
}
|
||||
if (rhs.type() == value_t::number_float)
|
||||
case (value_t::number_float):
|
||||
{
|
||||
return approx(lhs.m_value.number_float, rhs.m_value.number_float);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
else if (lhs_type == value_t::number_integer and rhs_type == value_t::number_float)
|
||||
{
|
||||
return lhs.m_value.number_integer ==
|
||||
static_cast<number_integer_t>(rhs.m_value.number_float);
|
||||
}
|
||||
else if (lhs_type == value_t::number_float and rhs_type == value_t::number_integer)
|
||||
{
|
||||
return approx(lhs.m_value.number_float,
|
||||
static_cast<number_float_t>(rhs.m_value.number_integer));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1959,9 +1937,9 @@ class basic_json
|
||||
{
|
||||
case (value_t::array):
|
||||
{
|
||||
return *lhs.m_value_array < *rhs.m_value.array;
|
||||
return *lhs.m_value.array < *rhs.m_value.array;
|
||||
}
|
||||
case (value_t::onject):
|
||||
case (value_t::object):
|
||||
{
|
||||
return *lhs.m_value.object < *rhs.m_value.object;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user