diff --git a/src/json.hpp b/src/json.hpp index 528c92b2..390d4e79 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -161,26 +161,6 @@ struct has_mapped_type std::is_integral()))>::value; }; -// taken from http://stackoverflow.com/questions/10711952/how-to-detect-existence-of-a-class-using-sfinae -// used to determine if json_traits is defined for a given type T -template -struct has_destructor -{ - template - static std::true_type detect(decltype(std::declval().~U())*); - - template - static std::false_type detect(...); - - static constexpr bool value = decltype(detect(0))::value; -}; - -template -struct has_json_traits -{ - static constexpr bool value = has_destructor>::value; -}; - struct to_json_fn { template @@ -1407,8 +1387,7 @@ class basic_json // auto j = json{{"a", json(not_equality_comparable{})}}; // // we can remove this constraint though, since lots of ctor are not explicit already - template >::value>> + template >::to_json(std::declval>()))> explicit basic_json(T &&val) : basic_json(json_traits>::to_json(std::forward(val))) { @@ -2775,24 +2754,19 @@ class basic_json // get_impl overload chosen if json_traits struct is specialized for type T // simply returns json_traits::from_json(*this); - template >::value>> - auto get_impl(T *) const -> decltype( - json_traits>::from_json(std::declval())) + // dual argument to avoid conflicting with get_impl overloads taking a pointer + template + auto get_impl(int, int) const -> decltype(json_traits>::from_json(*this)) { return json_traits>::from_json(*this); } - // this one is quite atrocious // this overload is chosen ONLY if json_traits struct is not specialized, and if the expression nlohmann::from_json(*this, T&) is valid // I chose to prefer the json_traits specialization if it exists, since it's a more advanced use. // But we can of course change this behaviour template - auto get_impl(T *) const -> enable_if_t< - not detail::has_json_traits>::value, - uncvref_t(), - std::declval()), - std::declval())>> + auto get_impl(long, long) const -> uncvref_t()), + std::declval())> { remove_cv_t ret; // I guess this output parameter is the only way to get ADL @@ -3108,11 +3082,16 @@ class basic_json */ template::value, int>::type = 0> - ValueType get() const + auto get() const -> decltype(get_impl(static_cast(nullptr))) { return get_impl(static_cast(nullptr)); } + template + auto get() const -> decltype(get_impl(0, 0)) + { + return get_impl(0, 0); + } /*! @brief get a pointer value (explicit)