diff --git a/src/json.hpp b/src/json.hpp index c7ca74d79..177c15321 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -1789,15 +1789,16 @@ class basic_json // - JSONSerializer::to_json exists for type T // - T is not a istream, nor convertible to basic_json (float, vectors, etc) template , - enable_if_t< - not std::is_base_of::value and - not std::is_same::value and - not detail::is_basic_json_nested_type::value and - detail::has_to_json::value, - int> = 0> - basic_json(T &&val) + enable_if_t::value and + not std::is_same::value and + not detail::is_basic_json_nested_type< + basic_json_t, U>::value and + detail::has_to_json::value, + int> = 0> + basic_json(T &&val) noexcept(noexcept(JSONSerializer::to_json( + std::declval(), std::forward(val)))) { - JSONSerializer>::to_json(*this, std::forward(val)); + JSONSerializer::to_json(*this, std::forward(val)); } /*! @@ -2959,14 +2960,18 @@ class basic_json // the latter is preferred if both are present (since it does not require a default construction of T) template < typename T, - enable_if_t>::value and - detail::has_from_json>::value and - not detail::has_non_default_from_json< - basic_json_t, uncvref_t>::value, - int> = 0> + enable_if_t< + not std::is_same>::value and + detail::has_from_json>::value and + not detail::has_non_default_from_json>::value, + int> = 0> // do we really want the uncvref ? if a user call get, shouldn't we + // i know there is a special behaviour for boolean_t* and such // static assert ? - auto get() const -> uncvref_t + auto get() const noexcept(noexcept(JSONSerializer>::from_json( + std::declval(), std::declval &>()))) + -> uncvref_t { using type = uncvref_t; static_assert(std::is_default_constructible::value && @@ -2981,14 +2986,13 @@ class basic_json // This overload is chosen when: // - T is not basic_json_t // - and JSONSerializer::from_json(basic_json const&) does not exist - // TODO add constexpr, noexcept(...) template < typename T, enable_if_t>::value and detail::has_non_default_from_json>::value, int> = 0> - uncvref_t get() const + constexpr uncvref_t get() const noexcept(noexcept(JSONSerializer::from_json(std::declval()))) { return JSONSerializer::from_json(*this); } diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c index b3b512e53..5dc2e0277 100644 --- a/src/json.hpp.re2c +++ b/src/json.hpp.re2c @@ -1789,15 +1789,16 @@ class basic_json // - JSONSerializer::to_json exists for type T // - T is not a istream, nor convertible to basic_json (float, vectors, etc) template , - enable_if_t< - not std::is_base_of::value and - not std::is_same::value and - not detail::is_basic_json_nested_type::value and - detail::has_to_json::value, - int> = 0> - basic_json(T &&val) + enable_if_t::value and + not std::is_same::value and + not detail::is_basic_json_nested_type< + basic_json_t, U>::value and + detail::has_to_json::value, + int> = 0> + basic_json(T &&val) noexcept(noexcept(JSONSerializer::to_json( + std::declval(), std::forward(val)))) { - JSONSerializer>::to_json(*this, std::forward(val)); + JSONSerializer::to_json(*this, std::forward(val)); } /*! @@ -2959,14 +2960,18 @@ class basic_json // the latter is preferred if both are present (since it does not require a default construction of T) template < typename T, - enable_if_t>::value and - detail::has_from_json>::value and - not detail::has_non_default_from_json< - basic_json_t, uncvref_t>::value, - int> = 0> + enable_if_t< + not std::is_same>::value and + detail::has_from_json>::value and + not detail::has_non_default_from_json>::value, + int> = 0> // do we really want the uncvref ? if a user call get, shouldn't we + // i know there is a special behaviour for boolean_t* and such // static assert ? - auto get() const -> uncvref_t + auto get() const noexcept(noexcept(JSONSerializer>::from_json( + std::declval(), std::declval &>()))) + -> uncvref_t { using type = uncvref_t; static_assert(std::is_default_constructible::value && @@ -2981,14 +2986,13 @@ class basic_json // This overload is chosen when: // - T is not basic_json_t // - and JSONSerializer::from_json(basic_json const&) does not exist - // TODO add constexpr, noexcept(...) template < typename T, enable_if_t>::value and detail::has_non_default_from_json>::value, int> = 0> - uncvref_t get() const + constexpr uncvref_t get() const noexcept(noexcept(JSONSerializer::from_json(std::declval()))) { return JSONSerializer::from_json(*this); }