This commit is contained in:
Fredrik Sandhei 2024-02-29 21:53:07 +00:00 committed by GitHub
commit 7793ac2fc5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 42 additions and 12 deletions

View File

@ -742,6 +742,13 @@ inline constexpr bool value_in_range_of(T val)
template<bool Value>
using bool_constant = std::integral_constant<bool, Value>;
template <typename T, typename BasicJsonType, typename U = uncvref_t<T>>
struct json_compatible_type
{
static constexpr bool value = !is_basic_json<U>::value && is_compatible_type<BasicJsonType, U>::value;
};
///////////////////////////////////////////////////////////////////////////////
// is_c_string
///////////////////////////////////////////////////////////////////////////////

View File

@ -3692,11 +3692,19 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
#endif
}
// template<typename ScalarType, typename std::enable_if<
// std::is_scalar<ScalarType>::value, int>::type = 0>
/// @brief comparison: equal
/// @sa https://json.nlohmann.me/api/basic_json/operator_eq/
template<typename ScalarType>
requires std::is_scalar_v<ScalarType>
bool operator==(ScalarType rhs) const noexcept
template <typename T,
std::enable_if<detail::json_compatible_type<T, basic_json_t>::value, int>::type = 0>
bool operator==(T rhs) const noexcept
{
return *this == basic_json(rhs);
}
/// @sa https://json.nlohmann.me/api/basic_json/operator_eq/
bool operator==(std::nullptr_t rhs) const noexcept
{
return *this == basic_json(rhs);
}
@ -3727,9 +3735,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
/// @brief comparison: 3-way
/// @sa https://json.nlohmann.me/api/basic_json/operator_spaceship/
template<typename ScalarType>
requires std::is_scalar_v<ScalarType>
std::partial_ordering operator<=>(ScalarType rhs) const noexcept // *NOPAD*
template <typename T>
requires detail::json_compatible_type<T, basic_json_t>::value
std::partial_ordering operator<=>(T rhs) const noexcept // *NOPAD*
{
return *this <=> basic_json(rhs); // *NOPAD*
}

View File

@ -4155,6 +4155,12 @@ inline constexpr bool value_in_range_of(T val)
template<bool Value>
using bool_constant = std::integral_constant<bool, Value>;
template <typename T, typename BasicJsonType, typename U = uncvref_t<T>>
struct json_compatible_type
{
static constexpr auto value = !is_basic_json<U>::value && is_compatible_type<BasicJsonType, U>::value;
};
///////////////////////////////////////////////////////////////////////////////
// is_c_string
///////////////////////////////////////////////////////////////////////////////
@ -22995,11 +23001,19 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
#endif
}
// template<typename ScalarType, typename std::enable_if<
// std::is_scalar<ScalarType>::value, int>::type = 0>
/// @brief comparison: equal
/// @sa https://json.nlohmann.me/api/basic_json/operator_eq/
template<typename ScalarType>
requires std::is_scalar_v<ScalarType>
bool operator==(ScalarType rhs) const noexcept
template <typename T,
std::enable_if<detail::json_compatible_type<T, basic_json_t>::value, int>::type = 0>
bool operator==(T rhs) const noexcept
{
return *this == basic_json(rhs);
}
/// @sa https://json.nlohmann.me/api/basic_json/operator_eq/
bool operator==(std::nullptr_t rhs) const noexcept
{
return *this == basic_json(rhs);
}
@ -23030,9 +23044,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
/// @brief comparison: 3-way
/// @sa https://json.nlohmann.me/api/basic_json/operator_spaceship/
template<typename ScalarType>
requires std::is_scalar_v<ScalarType>
std::partial_ordering operator<=>(ScalarType rhs) const noexcept // *NOPAD*
template <typename T>
requires detail::json_compatible_type<T, basic_json_t>::value
std::partial_ordering operator<=>(T rhs) const noexcept // *NOPAD*
{
return *this <=> basic_json(rhs); // *NOPAD*
}

View File

@ -357,6 +357,7 @@ TEST_CASE("lexicographical comparison operators")
CAPTURE(i)
CAPTURE(j)
CHECK((j_values[i] == j_values[j]) == expected_eq[i][j]);
CHECK(expected_eq[i][j] == (j_values[i] == j_values[j]));
}
}