diff --git a/include/nlohmann/detail/conversions/from_json.hpp b/include/nlohmann/detail/conversions/from_json.hpp index 03e8d367e..0245bc45f 100644 --- a/include/nlohmann/detail/conversions/from_json.hpp +++ b/include/nlohmann/detail/conversions/from_json.hpp @@ -34,7 +34,7 @@ void from_json(const BasicJsonType& j, typename std::nullptr_t& n) // overloads for basic_json template parameters template < typename BasicJsonType, typename ArithmeticType, - enable_if_t < std::is_arithmetic::value&& + enable_if_t < (std::is_arithmetic::value || is_128_bit_integral::value)&& !std::is_same::value, int > = 0 > void get_arithmetic_value(const BasicJsonType& j, ArithmeticType& val) diff --git a/include/nlohmann/detail/meta/type_traits.hpp b/include/nlohmann/detail/meta/type_traits.hpp index af23065ef..0d050d8ac 100644 --- a/include/nlohmann/detail/meta/type_traits.hpp +++ b/include/nlohmann/detail/meta/type_traits.hpp @@ -327,10 +327,16 @@ template struct is_constructible_array_type : is_constructible_array_type_impl {}; +// true for types with up to 64 bit template struct is_64_bit : std::integral_constant < bool, (sizeof(NumberType) <= 8) > {}; +// true for types with at least 64 bit that con be convert from 64 bit integers +template +struct is_128_bit_integral : std::integral_constant < bool, (((std::is_signed::value&& std::is_convertible::value) || (std::is_unsigned::value&& std::is_convertible::value))&& !is_64_bit::value) > +{}; + template struct is_compatible_integer_type_impl : std::false_type {}; @@ -358,8 +364,7 @@ template struct is_compatible_integer_type_impl < RealIntegerType, CompatibleNumberIntegerType, enable_if_t < std::is_same::value&& !std::is_integral::value&& - (std::is_unsigned::value&& std::is_convertible::value || !std::is_unsigned::value&& std::is_convertible::value)&& - !is_64_bit::value >> + is_128_bit_integral::value >> { static constexpr auto value = true; }; diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index eb3666481..9710b999c 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -3146,6 +3146,10 @@ template struct is_64_bit : std::integral_constant < bool, (sizeof(NumberType) <= 8) > {}; +template +struct is_128_bit_integral : std::integral_constant < bool, (((std::is_signed::value&& std::is_convertible::value) || (std::is_unsigned::value&& std::is_convertible::value))&& !is_64_bit::value) > +{}; + template struct is_compatible_integer_type_impl : std::false_type {}; @@ -3173,8 +3177,7 @@ template struct is_compatible_integer_type_impl < RealIntegerType, CompatibleNumberIntegerType, enable_if_t < std::is_same::value&& !std::is_integral::value&& - (std::is_unsigned::value&& std::is_convertible::value || !std::is_unsigned::value&& std::is_convertible::value)&& - !is_64_bit::value >> + is_128_bit_integral::value >> { static constexpr auto value = true; }; @@ -3315,7 +3318,7 @@ void from_json(const BasicJsonType& j, typename std::nullptr_t& n) // overloads for basic_json template parameters template < typename BasicJsonType, typename ArithmeticType, - enable_if_t < std::is_arithmetic::value&& + enable_if_t < (std::is_arithmetic::value || is_128_bit_integral::value)&& !std::is_same::value, int > = 0 > void get_arithmetic_value(const BasicJsonType& j, ArithmeticType& val)