diff --git a/src/json.hpp b/src/json.hpp index 1188ead4..98f78262 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -495,11 +495,11 @@ void get_arithmetic_value(Json const &j, ArithmeticType &val) { // unsigned must be checked first, since is_number_integer() == true for unsigned if (j.is_number_unsigned()) - val = *j.template get_ptr(); + val = static_cast(*j.template get_ptr()); else if (j.is_number_integer()) - val = *j.template get_ptr(); + val = static_cast(*j.template get_ptr()); else if (j.is_number_float()) - val = *j.template get_ptr(); + val = static_cast(*j.template get_ptr()); else throw std::domain_error("type must be number, but is " + type_name(j)); } @@ -523,7 +523,7 @@ template ::value, int> = 0> void to_json(Json &j, FloatType val) noexcept { - external_constructor::construct(j, val); + external_constructor::construct(j, static_cast(val)); } @@ -534,7 +534,7 @@ template < int> = 0> void to_json(Json &j, CompatibleNumberUnsignedType val) noexcept { - external_constructor::construct(j, val); + external_constructor::construct(j, static_cast(val)); } template < @@ -544,7 +544,7 @@ template < int> = 0> void to_json(Json &j, CompatibleNumberIntegerType val) noexcept { - external_constructor::construct(j, val); + external_constructor::construct(j, static_cast(val)); } template (); + val = static_cast(*j.template get_ptr()); else if (j.is_number_integer()) - val = *j.template get_ptr(); + val = static_cast(*j.template get_ptr()); else if (j.is_number_float()) - val = *j.template get_ptr(); + val = static_cast(*j.template get_ptr()); else if (j.is_boolean()) - val = *j.template get_ptr(); + val = static_cast(*j.template get_ptr()); else throw std::domain_error("type must be number, but is " + type_name(j)); } -template -constexpr auto has_adl_from_json(int) -> decltype(from_json(std::declval(), std::declval()), true) -{ - return true; -} - -template -constexpr bool has_adl_from_json(long) -{ - return false; -} - -template -constexpr auto has_adl_to_json(int) -> decltype(to_json(std::declval(), std::declval()), true) -{ - return true; -} - -template -constexpr bool has_adl_to_json(long) -{ - return false; -} - struct to_json_fn { - private: - template (0), int> = 0> - auto operator()(Json&& j, T&& val) const - noexcept(noexcept(to_json(std::forward(j), std::forward(val)))) - -> decltype(to_json(std::forward(j), std::forward(val)), + template + auto call(int, Json& j, T&& val) const + noexcept(noexcept(to_json(j, std::forward(val)))) + -> decltype(to_json(j, std::forward(val)), void()) { - return to_json(std::forward(j), std::forward(val)); + return to_json(j, std::forward(val)); } - template (0), int> = 0> - void operator()(Json&&, T&&) const noexcept + template + void call(long, Json&, T&&) const noexcept { - static_assert(has_adl_to_json(0), "to_json method in T's namespace can not be called"); + static_assert(sizeof(Json) == 0, "to_json method in T's namespace can not be called"); } public: @@ -768,20 +743,20 @@ public: struct from_json_fn { - private: - template (0), int> = 0> - auto operator()(Json&& j, T& val) const - noexcept(noexcept(from_json(std::forward(j), val))) - -> decltype(from_json(std::forward(j), val), void()) - { - return from_json(std::forward(j), val); - } - - template (0), int> = 0> - void operator()(Json&&, T&) const noexcept - { - static_assert(has_adl_from_json(0), "from_json method in T's namespace can not be called"); - } +private: + template + auto call(int, Json const &j, T &val) const + noexcept(noexcept(from_json(j, val))) + -> decltype(from_json(j, val), void()) + { + return from_json(j, val); + } + + template + void call(long, Json const&, T&) const noexcept + { + static_assert(sizeof(Json) == 0, "from_json method in T's namespace can not be called"); + } public: template