🔀 merge branch 'develop' into feature/manual_lexer
This commit is contained in:
commit
d62d48fc48
2 changed files with 123 additions and 0 deletions
88
src/json.hpp
88
src/json.hpp
|
@ -6395,6 +6395,28 @@ class basic_json
|
||||||
return operator<(lhs_type, rhs_type);
|
return operator<(lhs_type, rhs_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@brief comparison: less than
|
||||||
|
@copydoc operator<(const_reference, const_reference)
|
||||||
|
*/
|
||||||
|
template<typename ScalarType, typename std::enable_if<
|
||||||
|
std::is_scalar<ScalarType>::value, int>::type = 0>
|
||||||
|
friend bool operator<(const_reference lhs, const ScalarType rhs) noexcept
|
||||||
|
{
|
||||||
|
return (lhs < basic_json(rhs));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@brief comparison: less than
|
||||||
|
@copydoc operator<(const_reference, const_reference)
|
||||||
|
*/
|
||||||
|
template<typename ScalarType, typename std::enable_if<
|
||||||
|
std::is_scalar<ScalarType>::value, int>::type = 0>
|
||||||
|
friend bool operator<(const ScalarType lhs, const_reference rhs) noexcept
|
||||||
|
{
|
||||||
|
return (basic_json(lhs) < rhs);
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief comparison: less than or equal
|
@brief comparison: less than or equal
|
||||||
|
|
||||||
|
@ -6417,6 +6439,28 @@ class basic_json
|
||||||
return not (rhs < lhs);
|
return not (rhs < lhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@brief comparison: less than or equal
|
||||||
|
@copydoc operator<=(const_reference, const_reference)
|
||||||
|
*/
|
||||||
|
template<typename ScalarType, typename std::enable_if<
|
||||||
|
std::is_scalar<ScalarType>::value, int>::type = 0>
|
||||||
|
friend bool operator<=(const_reference lhs, const ScalarType rhs) noexcept
|
||||||
|
{
|
||||||
|
return (lhs <= basic_json(rhs));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@brief comparison: less than or equal
|
||||||
|
@copydoc operator<=(const_reference, const_reference)
|
||||||
|
*/
|
||||||
|
template<typename ScalarType, typename std::enable_if<
|
||||||
|
std::is_scalar<ScalarType>::value, int>::type = 0>
|
||||||
|
friend bool operator<=(const ScalarType lhs, const_reference rhs) noexcept
|
||||||
|
{
|
||||||
|
return (basic_json(lhs) <= rhs);
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief comparison: greater than
|
@brief comparison: greater than
|
||||||
|
|
||||||
|
@ -6439,6 +6483,28 @@ class basic_json
|
||||||
return not (lhs <= rhs);
|
return not (lhs <= rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@brief comparison: greater than
|
||||||
|
@copydoc operator>(const_reference, const_reference)
|
||||||
|
*/
|
||||||
|
template<typename ScalarType, typename std::enable_if<
|
||||||
|
std::is_scalar<ScalarType>::value, int>::type = 0>
|
||||||
|
friend bool operator>(const_reference lhs, const ScalarType rhs) noexcept
|
||||||
|
{
|
||||||
|
return (lhs > basic_json(rhs));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@brief comparison: greater than
|
||||||
|
@copydoc operator>(const_reference, const_reference)
|
||||||
|
*/
|
||||||
|
template<typename ScalarType, typename std::enable_if<
|
||||||
|
std::is_scalar<ScalarType>::value, int>::type = 0>
|
||||||
|
friend bool operator>(const ScalarType lhs, const_reference rhs) noexcept
|
||||||
|
{
|
||||||
|
return (basic_json(lhs) > rhs);
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief comparison: greater than or equal
|
@brief comparison: greater than or equal
|
||||||
|
|
||||||
|
@ -6461,6 +6527,28 @@ class basic_json
|
||||||
return not (lhs < rhs);
|
return not (lhs < rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@brief comparison: greater than or equal
|
||||||
|
@copydoc operator>=(const_reference, const_reference)
|
||||||
|
*/
|
||||||
|
template<typename ScalarType, typename std::enable_if<
|
||||||
|
std::is_scalar<ScalarType>::value, int>::type = 0>
|
||||||
|
friend bool operator>=(const_reference lhs, const ScalarType rhs) noexcept
|
||||||
|
{
|
||||||
|
return (lhs >= basic_json(rhs));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@brief comparison: greater than or equal
|
||||||
|
@copydoc operator>=(const_reference, const_reference)
|
||||||
|
*/
|
||||||
|
template<typename ScalarType, typename std::enable_if<
|
||||||
|
std::is_scalar<ScalarType>::value, int>::type = 0>
|
||||||
|
friend bool operator>=(const ScalarType lhs, const_reference rhs) noexcept
|
||||||
|
{
|
||||||
|
return (basic_json(lhs) >= rhs);
|
||||||
|
}
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -975,4 +975,39 @@ TEST_CASE("regression tests")
|
||||||
// check if serializations match
|
// check if serializations match
|
||||||
CHECK(json::to_cbor(j2) == vec2);
|
CHECK(json::to_cbor(j2) == vec2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SECTION("issue #512 - use of overloaded operator '<=' is ambiguous")
|
||||||
|
{
|
||||||
|
json j;
|
||||||
|
j["a"] = 5;
|
||||||
|
|
||||||
|
// json op scalar
|
||||||
|
CHECK(j["a"] == 5);
|
||||||
|
CHECK(j["a"] != 4);
|
||||||
|
|
||||||
|
CHECK(j["a"] <= 7);
|
||||||
|
CHECK(j["a"] < 7);
|
||||||
|
CHECK(j["a"] >= 3);
|
||||||
|
CHECK(j["a"] > 3);
|
||||||
|
|
||||||
|
|
||||||
|
CHECK(not(j["a"] <= 4));
|
||||||
|
CHECK(not(j["a"] < 4));
|
||||||
|
CHECK(not(j["a"] >= 6));
|
||||||
|
CHECK(not(j["a"] > 6));
|
||||||
|
|
||||||
|
// scalar op json
|
||||||
|
CHECK(5 == j["a"]);
|
||||||
|
CHECK(4 != j["a"]);
|
||||||
|
|
||||||
|
CHECK(7 >= j["a"]);
|
||||||
|
CHECK(7 > j["a"]);
|
||||||
|
CHECK(3 <= j["a"]);
|
||||||
|
CHECK(3 < j["a"]);
|
||||||
|
|
||||||
|
CHECK(not(4 >= j["a"]));
|
||||||
|
CHECK(not(4 > j["a"]));
|
||||||
|
CHECK(not(6 <= j["a"]));
|
||||||
|
CHECK(not(6 < j["a"]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue