1
0
mirror of https://github.com/nlohmann/json.git synced 2025-08-07 18:02:57 +03:00

Properly constrain the basic_json conversion operator

Fixes #2491
This commit is contained in:
Louis Dionne
2021-06-17 13:17:43 -04:00
parent 926fab47d0
commit b0e5965d71
5 changed files with 41 additions and 19 deletions

View File

@@ -3359,17 +3359,19 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
@since version 1.0.0
*/
template < typename ValueType, typename std::enable_if <
!std::is_pointer<ValueType>::value&&
!std::is_same<ValueType, detail::json_ref<basic_json>>::value&&
!std::is_same<ValueType, typename string_t::value_type>::value&&
!detail::is_basic_json<ValueType>::value
&& !std::is_same<ValueType, std::initializer_list<typename string_t::value_type>>::value
detail::conjunction <
detail::negation<std::is_pointer<ValueType>>,
detail::negation<std::is_same<ValueType, detail::json_ref<basic_json>>>,
detail::negation<std::is_same<ValueType, typename string_t::value_type>>,
detail::negation<detail::is_basic_json<ValueType>>,
detail::negation<std::is_same<ValueType, std::initializer_list<typename string_t::value_type>>>,
#if defined(JSON_HAS_CPP_17) && (defined(__GNUC__) || (defined(_MSC_VER) && _MSC_VER >= 1910 && _MSC_VER <= 1914))
&& !std::is_same<ValueType, typename std::string_view>::value
detail::negation<std::is_same<ValueType, std::string_view>>,
#endif
&& detail::is_detected<detail::get_template_function, const basic_json_t&, ValueType>::value
, int >::type = 0 >
JSON_EXPLICIT operator ValueType() const
detail::is_detected_lazy<detail::get_template_function, const basic_json_t&, ValueType>
>::value, int >::type = 0 >
JSON_EXPLICIT operator ValueType() const
{
// delegate the call to get<>() const
return get<ValueType>();
@@ -8907,7 +8909,7 @@ template<>
inline void swap<nlohmann::json>(nlohmann::json& j1, nlohmann::json& j2) noexcept( // NOLINT(readability-inconsistent-declaration-parameter-name)
is_nothrow_move_constructible<nlohmann::json>::value&& // NOLINT(misc-redundant-expression)
is_nothrow_move_assignable<nlohmann::json>::value
)
)
{
j1.swap(j2);
}