:green_heart: add trait for 128 bit integers
diff --git a/include/nlohmann/detail/conversions/from_json.hpp b/include/nlohmann/detail/conversions/from_json.hpp index 03e8d36..0245bc4 100644 --- a/include/nlohmann/detail/conversions/from_json.hpp +++ b/include/nlohmann/detail/conversions/from_json.hpp
@@ -34,7 +34,7 @@ // overloads for basic_json template parameters template < typename BasicJsonType, typename ArithmeticType, - enable_if_t < std::is_arithmetic<ArithmeticType>::value&& + enable_if_t < (std::is_arithmetic<ArithmeticType>::value || is_128_bit_integral<ArithmeticType>::value)&& !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::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 af23065..0d050d8 100644 --- a/include/nlohmann/detail/meta/type_traits.hpp +++ b/include/nlohmann/detail/meta/type_traits.hpp
@@ -327,10 +327,16 @@ struct is_constructible_array_type : is_constructible_array_type_impl<BasicJsonType, ConstructibleArrayType> {}; +// true for types with up to 64 bit template<typename NumberType> 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<typename NumberType> +struct is_128_bit_integral : std::integral_constant < bool, (((std::is_signed<NumberType>::value&& std::is_convertible<std::int64_t, NumberType>::value) || (std::is_unsigned<NumberType>::value&& std::is_convertible<std::uint64_t, NumberType>::value))&& !is_64_bit<NumberType>::value) > +{}; + template<typename RealIntegerType, typename CompatibleNumberIntegerType, typename = void> struct is_compatible_integer_type_impl : std::false_type {}; @@ -358,8 +364,7 @@ struct is_compatible_integer_type_impl < RealIntegerType, CompatibleNumberIntegerType, enable_if_t < std::is_same<RealIntegerType, CompatibleNumberIntegerType>::value&& !std::is_integral<CompatibleNumberIntegerType>::value&& - (std::is_unsigned<RealIntegerType>::value&& std::is_convertible<std::uint64_t, RealIntegerType>::value || !std::is_unsigned<RealIntegerType>::value&& std::is_convertible<std::int64_t, RealIntegerType>::value)&& - !is_64_bit<RealIntegerType>::value >> + is_128_bit_integral<CompatibleNumberIntegerType>::value >> { static constexpr auto value = true; };
diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index eb36664..9710b99 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp
@@ -3146,6 +3146,10 @@ struct is_64_bit : std::integral_constant < bool, (sizeof(NumberType) <= 8) > {}; +template<typename NumberType> +struct is_128_bit_integral : std::integral_constant < bool, (((std::is_signed<NumberType>::value&& std::is_convertible<std::int64_t, NumberType>::value) || (std::is_unsigned<NumberType>::value&& std::is_convertible<std::uint64_t, NumberType>::value))&& !is_64_bit<NumberType>::value) > +{}; + template<typename RealIntegerType, typename CompatibleNumberIntegerType, typename = void> struct is_compatible_integer_type_impl : std::false_type {}; @@ -3173,8 +3177,7 @@ struct is_compatible_integer_type_impl < RealIntegerType, CompatibleNumberIntegerType, enable_if_t < std::is_same<RealIntegerType, CompatibleNumberIntegerType>::value&& !std::is_integral<CompatibleNumberIntegerType>::value&& - (std::is_unsigned<RealIntegerType>::value&& std::is_convertible<std::uint64_t, RealIntegerType>::value || !std::is_unsigned<RealIntegerType>::value&& std::is_convertible<std::int64_t, RealIntegerType>::value)&& - !is_64_bit<RealIntegerType>::value >> + is_128_bit_integral<CompatibleNumberIntegerType>::value >> { static constexpr auto value = true; }; @@ -3315,7 +3318,7 @@ // overloads for basic_json template parameters template < typename BasicJsonType, typename ArithmeticType, - enable_if_t < std::is_arithmetic<ArithmeticType>::value&& + enable_if_t < (std::is_arithmetic<ArithmeticType>::value || is_128_bit_integral<ArithmeticType>::value)&& !std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value, int > = 0 > void get_arithmetic_value(const BasicJsonType& j, ArithmeticType& val)