mirror of
https://github.com/nlohmann/json.git
synced 2024-11-23 22:19:02 +08:00
💚 add trait for 128 bit integers
This commit is contained in:
parent
0f1f5052bf
commit
c13ecd5344
@ -34,7 +34,7 @@ void from_json(const BasicJsonType& j, typename std::nullptr_t& n)
|
|||||||
|
|
||||||
// overloads for basic_json template parameters
|
// overloads for basic_json template parameters
|
||||||
template < typename BasicJsonType, typename ArithmeticType,
|
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,
|
!std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value,
|
||||||
int > = 0 >
|
int > = 0 >
|
||||||
void get_arithmetic_value(const BasicJsonType& j, ArithmeticType& val)
|
void get_arithmetic_value(const BasicJsonType& j, ArithmeticType& val)
|
||||||
|
@ -327,10 +327,16 @@ template<typename BasicJsonType, typename ConstructibleArrayType>
|
|||||||
struct is_constructible_array_type
|
struct is_constructible_array_type
|
||||||
: is_constructible_array_type_impl<BasicJsonType, ConstructibleArrayType> {};
|
: is_constructible_array_type_impl<BasicJsonType, ConstructibleArrayType> {};
|
||||||
|
|
||||||
|
// true for types with up to 64 bit
|
||||||
template<typename NumberType>
|
template<typename NumberType>
|
||||||
struct is_64_bit : std::integral_constant < bool, (sizeof(NumberType) <= 8) >
|
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,
|
template<typename RealIntegerType, typename CompatibleNumberIntegerType,
|
||||||
typename = void>
|
typename = void>
|
||||||
struct is_compatible_integer_type_impl : std::false_type {};
|
struct is_compatible_integer_type_impl : std::false_type {};
|
||||||
@ -358,8 +364,7 @@ template<typename RealIntegerType, typename CompatibleNumberIntegerType>
|
|||||||
struct is_compatible_integer_type_impl < RealIntegerType, CompatibleNumberIntegerType,
|
struct is_compatible_integer_type_impl < RealIntegerType, CompatibleNumberIntegerType,
|
||||||
enable_if_t < std::is_same<RealIntegerType, CompatibleNumberIntegerType>::value&&
|
enable_if_t < std::is_same<RealIntegerType, CompatibleNumberIntegerType>::value&&
|
||||||
!std::is_integral<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_128_bit_integral<CompatibleNumberIntegerType>::value >>
|
||||||
!is_64_bit<RealIntegerType>::value >>
|
|
||||||
{
|
{
|
||||||
static constexpr auto value = true;
|
static constexpr auto value = true;
|
||||||
};
|
};
|
||||||
|
@ -3146,6 +3146,10 @@ template<typename NumberType>
|
|||||||
struct is_64_bit : std::integral_constant < bool, (sizeof(NumberType) <= 8) >
|
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,
|
template<typename RealIntegerType, typename CompatibleNumberIntegerType,
|
||||||
typename = void>
|
typename = void>
|
||||||
struct is_compatible_integer_type_impl : std::false_type {};
|
struct is_compatible_integer_type_impl : std::false_type {};
|
||||||
@ -3173,8 +3177,7 @@ template<typename RealIntegerType, typename CompatibleNumberIntegerType>
|
|||||||
struct is_compatible_integer_type_impl < RealIntegerType, CompatibleNumberIntegerType,
|
struct is_compatible_integer_type_impl < RealIntegerType, CompatibleNumberIntegerType,
|
||||||
enable_if_t < std::is_same<RealIntegerType, CompatibleNumberIntegerType>::value&&
|
enable_if_t < std::is_same<RealIntegerType, CompatibleNumberIntegerType>::value&&
|
||||||
!std::is_integral<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_128_bit_integral<CompatibleNumberIntegerType>::value >>
|
||||||
!is_64_bit<RealIntegerType>::value >>
|
|
||||||
{
|
{
|
||||||
static constexpr auto value = true;
|
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
|
// overloads for basic_json template parameters
|
||||||
template < typename BasicJsonType, typename ArithmeticType,
|
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,
|
!std::is_same<ArithmeticType, typename BasicJsonType::boolean_t>::value,
|
||||||
int > = 0 >
|
int > = 0 >
|
||||||
void get_arithmetic_value(const BasicJsonType& j, ArithmeticType& val)
|
void get_arithmetic_value(const BasicJsonType& j, ArithmeticType& val)
|
||||||
|
Loading…
Reference in New Issue
Block a user