From 77967e65485451598207e71d987abdec7586c080 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20DELRIEU?= Date: Wed, 5 Sep 2018 16:56:45 +0200 Subject: [PATCH] refactor is_compatible_integer_type --- include/nlohmann/detail/meta/type_traits.hpp | 25 ++++++++++---------- single_include/nlohmann/json.hpp | 25 ++++++++++---------- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/include/nlohmann/detail/meta/type_traits.hpp b/include/nlohmann/detail/meta/type_traits.hpp index 273d80cb..9dfad61e 100644 --- a/include/nlohmann/detail/meta/type_traits.hpp +++ b/include/nlohmann/detail/meta/type_traits.hpp @@ -137,31 +137,32 @@ template struct is_compatible_array_type : is_compatible_array_type_impl {}; -template +template struct is_compatible_integer_type_impl : std::false_type {}; -template -struct is_compatible_integer_type_impl +template +struct is_compatible_integer_type_impl < + RealIntegerType, CompatibleNumberIntegerType, + enable_if_t::value and + std::is_integral::value and + not std::is_same::value >> { // is there an assert somewhere on overflows? using RealLimits = std::numeric_limits; using CompatibleLimits = std::numeric_limits; static constexpr auto value = - std::is_constructible::value and + std::is_constructible::value and CompatibleLimits::is_integer and RealLimits::is_signed == CompatibleLimits::is_signed; }; -template +template struct is_compatible_integer_type -{ - static constexpr auto value = - is_compatible_integer_type_impl < - std::is_integral::value and - not std::is_same::value, - RealIntegerType, CompatibleNumberIntegerType > ::value; -}; + : is_compatible_integer_type_impl {}; // trait checking if JSONSerializer::from_json(json const&, udt&) exists template diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 15ff8765..4cca4b5f 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -517,31 +517,32 @@ template struct is_compatible_array_type : is_compatible_array_type_impl {}; -template +template struct is_compatible_integer_type_impl : std::false_type {}; -template -struct is_compatible_integer_type_impl +template +struct is_compatible_integer_type_impl < + RealIntegerType, CompatibleNumberIntegerType, + enable_if_t::value and + std::is_integral::value and + not std::is_same::value >> { // is there an assert somewhere on overflows? using RealLimits = std::numeric_limits; using CompatibleLimits = std::numeric_limits; static constexpr auto value = - std::is_constructible::value and + std::is_constructible::value and CompatibleLimits::is_integer and RealLimits::is_signed == CompatibleLimits::is_signed; }; -template +template struct is_compatible_integer_type -{ - static constexpr auto value = - is_compatible_integer_type_impl < - std::is_integral::value and - not std::is_same::value, - RealIntegerType, CompatibleNumberIntegerType > ::value; -}; + : is_compatible_integer_type_impl {}; // trait checking if JSONSerializer::from_json(json const&, udt&) exists template