From fbf6df63d9e16171abdcf47b6d699a1b19aaf1f9 Mon Sep 17 00:00:00 2001 From: Anthony VH Date: Wed, 13 Jan 2021 00:12:51 +0100 Subject: [PATCH] Enable member function calls in trailing return decltype expressions for older compilers. --- include/nlohmann/json.hpp | 27 +++++++++++++++------------ single_include/nlohmann/json.hpp | 27 +++++++++++++++------------ 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 500acb36e..a7adb724f 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -2908,7 +2908,6 @@ class basic_json - @ref json_serializer does not have a `from_json()` method of the form `ValueType from_json(const basic_json&)` - @tparam ValueTypeCV the provided value type @tparam ValueType the returned value type @return copy of the JSON value, converted to @a ValueType @@ -2924,9 +2923,9 @@ class basic_json @since version 2.1.0 */ - template < typename ValueTypeCV, typename ValueType = detail::uncvref_t, + template < typename ValueType, detail::enable_if_t < - detail::is_default_constructible::value && + detail::is_default_constructible::value&& detail::has_from_json::value, int > = 0 > ValueType get_impl(detail::priority_tag<0> /*unused*/) const noexcept(noexcept( @@ -2948,7 +2947,7 @@ class basic_json The function is equivalent to executing @code {.cpp} - return JSONSerializer::from_json(*this); + return JSONSerializer::from_json(*this); @endcode This overloads is chosen if: @@ -2959,7 +2958,6 @@ class basic_json @note If @ref json_serializer has both overloads of `from_json()`, this one is chosen. - @tparam ValueTypeCV the provided value type @tparam ValueType the returned value type @return copy of the JSON value, converted to @a ValueType @@ -2968,7 +2966,7 @@ class basic_json @since version 2.1.0 */ - template < typename ValueTypeCV, typename ValueType = detail::uncvref_t, + template < typename ValueType, detail::enable_if_t < detail::has_non_default_from_json::value, int > = 0 > @@ -2993,7 +2991,8 @@ class basic_json @since version 3.2.0 */ - template < typename BasicJsonType, detail::enable_if_t < + template < typename BasicJsonType, + detail::enable_if_t < detail::is_basic_json::value, int > = 0 > BasicJsonType get_impl(detail::priority_tag<2> /*unused*/) const @@ -3015,7 +3014,8 @@ class basic_json @since version 2.1.0 */ - template::value, int> = 0> basic_json get_impl(detail::priority_tag<3> /*unused*/) const @@ -3027,8 +3027,10 @@ class basic_json @brief get a pointer value (explicit) @copydoc get() */ - template::value, int> = 0> + template::value, + int> = 0> constexpr auto get_impl(detail::priority_tag<4> /*unused*/) const noexcept -> decltype(std::declval().template get_ptr()) { @@ -3061,8 +3063,9 @@ class basic_json @since version 2.1.0 */ template < typename ValueTypeCV, typename ValueType = detail::uncvref_t> - constexpr auto get() const noexcept(noexcept(get_impl(detail::priority_tag<4> {}))) - -> decltype(get_impl(detail::priority_tag<4> {})) + constexpr auto get() const noexcept( + noexcept(std::declval().template get_impl(detail::priority_tag<4> {}))) + -> decltype(std::declval().template get_impl(detail::priority_tag<4> {})) { // we cannot static_assert on ValueTypeCV being non-const, because // there is support for get(), which is why we diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 004850c3a..fd01826b4 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -19667,7 +19667,6 @@ class basic_json - @ref json_serializer does not have a `from_json()` method of the form `ValueType from_json(const basic_json&)` - @tparam ValueTypeCV the provided value type @tparam ValueType the returned value type @return copy of the JSON value, converted to @a ValueType @@ -19683,9 +19682,9 @@ class basic_json @since version 2.1.0 */ - template < typename ValueTypeCV, typename ValueType = detail::uncvref_t, + template < typename ValueType, detail::enable_if_t < - detail::is_default_constructible::value && + detail::is_default_constructible::value&& detail::has_from_json::value, int > = 0 > ValueType get_impl(detail::priority_tag<0> /*unused*/) const noexcept(noexcept( @@ -19707,7 +19706,7 @@ class basic_json The function is equivalent to executing @code {.cpp} - return JSONSerializer::from_json(*this); + return JSONSerializer::from_json(*this); @endcode This overloads is chosen if: @@ -19718,7 +19717,6 @@ class basic_json @note If @ref json_serializer has both overloads of `from_json()`, this one is chosen. - @tparam ValueTypeCV the provided value type @tparam ValueType the returned value type @return copy of the JSON value, converted to @a ValueType @@ -19727,7 +19725,7 @@ class basic_json @since version 2.1.0 */ - template < typename ValueTypeCV, typename ValueType = detail::uncvref_t, + template < typename ValueType, detail::enable_if_t < detail::has_non_default_from_json::value, int > = 0 > @@ -19752,7 +19750,8 @@ class basic_json @since version 3.2.0 */ - template < typename BasicJsonType, detail::enable_if_t < + template < typename BasicJsonType, + detail::enable_if_t < detail::is_basic_json::value, int > = 0 > BasicJsonType get_impl(detail::priority_tag<2> /*unused*/) const @@ -19774,7 +19773,8 @@ class basic_json @since version 2.1.0 */ - template::value, int> = 0> basic_json get_impl(detail::priority_tag<3> /*unused*/) const @@ -19786,8 +19786,10 @@ class basic_json @brief get a pointer value (explicit) @copydoc get() */ - template::value, int> = 0> + template::value, + int> = 0> constexpr auto get_impl(detail::priority_tag<4> /*unused*/) const noexcept -> decltype(std::declval().template get_ptr()) { @@ -19820,8 +19822,9 @@ class basic_json @since version 2.1.0 */ template < typename ValueTypeCV, typename ValueType = detail::uncvref_t> - constexpr auto get() const noexcept(noexcept(get_impl(detail::priority_tag<4> {}))) - -> decltype(get_impl(detail::priority_tag<4> {})) + constexpr auto get() const noexcept( + noexcept(std::declval().template get_impl(detail::priority_tag<4> {}))) + -> decltype(std::declval().template get_impl(detail::priority_tag<4> {})) { // we cannot static_assert on ValueTypeCV being non-const, because // there is support for get(), which is why we