Create a concept for compatible types and use it instead of SFINAE.

This commit is contained in:
Fredrik Sandhei 2023-10-08 13:12:54 +02:00
parent d21abfc35e
commit 1eb5d38f1c
2 changed files with 7 additions and 5 deletions

View File

@ -684,6 +684,11 @@ inline constexpr bool value_in_range_of(T val)
template<bool Value> template<bool Value>
using bool_constant = std::integral_constant<bool, Value>; using bool_constant = std::integral_constant<bool, Value>;
#ifdef JSON_HAS_CPP_20
template <typename T, typename BasicJsonType>
concept CompatibleType = !is_basic_json<uncvref_t<T>>::value && is_compatible_type<BasicJsonType, uncvref_t<T>>::value;
#endif
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// is_c_string // is_c_string
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////

View File

@ -3694,11 +3694,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
/// @brief comparison: equal /// @brief comparison: equal
/// @sa https://json.nlohmann.me/api/basic_json/operator_eq/ /// @sa https://json.nlohmann.me/api/basic_json/operator_eq/
template < typename CompatibleType, template <detail::CompatibleType<basic_json_t> T>
typename U = detail::uncvref_t<CompatibleType>, bool operator==(T rhs) const noexcept
detail::enable_if_t <
!detail::is_basic_json<U>::value && detail::is_compatible_type<basic_json_t, U>::value, int > = 0 >
bool operator==(CompatibleType rhs) const noexcept
{ {
return *this == basic_json(rhs); return *this == basic_json(rhs);
} }