From 924e95c6e801937e890178741fc286a86090df33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20DELRIEU?= <theo.delrieu@tanker.io> Date: Wed, 5 Sep 2018 16:42:55 +0200 Subject: [PATCH] refactor is_compatible_string_type --- include/nlohmann/detail/meta/type_traits.hpp | 22 +++++++++----------- single_include/nlohmann/json.hpp | 22 +++++++++----------- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/include/nlohmann/detail/meta/type_traits.hpp b/include/nlohmann/detail/meta/type_traits.hpp index 1714a3d6..d993bc17 100644 --- a/include/nlohmann/detail/meta/type_traits.hpp +++ b/include/nlohmann/detail/meta/type_traits.hpp @@ -90,25 +90,23 @@ template <typename BasicJsonType, typename CompatibleObjectType> struct is_compatible_object_type : is_compatible_object_type_impl<BasicJsonType, CompatibleObjectType> {}; -template<bool B, class RealType, class CompatibleStringType> +template <typename BasicJsonType, typename CompatibleStringType, + typename = void> struct is_compatible_string_type_impl : std::false_type {}; -template<class RealType, class CompatibleStringType> -struct is_compatible_string_type_impl<true, RealType, CompatibleStringType> +template <typename BasicJsonType, typename CompatibleStringType> +struct is_compatible_string_type_impl < + BasicJsonType, CompatibleStringType, + enable_if_t<is_detected_exact<typename BasicJsonType::string_t::value_type, + value_type_t, CompatibleStringType>::value >> { static constexpr auto value = - std::is_same<typename RealType::value_type, typename CompatibleStringType::value_type>::value and - std::is_constructible<RealType, CompatibleStringType>::value; + std::is_constructible<typename BasicJsonType::string_t, CompatibleStringType>::value; }; -template<class BasicJsonType, class CompatibleStringType> +template <typename BasicJsonType, typename CompatibleStringType> struct is_compatible_string_type -{ - static auto constexpr value = is_compatible_string_type_impl < - conjunction<negation<std::is_same<void, CompatibleStringType>>, - is_detected<value_type_t, CompatibleStringType>>::value, - typename BasicJsonType::string_t, CompatibleStringType >::value; -}; + : is_compatible_string_type_impl<BasicJsonType, CompatibleStringType> {}; template<typename BasicJsonType, typename T> struct is_basic_json_nested_type diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index cfadee2d..ce08aab8 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -470,25 +470,23 @@ template <typename BasicJsonType, typename CompatibleObjectType> struct is_compatible_object_type : is_compatible_object_type_impl<BasicJsonType, CompatibleObjectType> {}; -template<bool B, class RealType, class CompatibleStringType> +template <typename BasicJsonType, typename CompatibleStringType, + typename = void> struct is_compatible_string_type_impl : std::false_type {}; -template<class RealType, class CompatibleStringType> -struct is_compatible_string_type_impl<true, RealType, CompatibleStringType> +template <typename BasicJsonType, typename CompatibleStringType> +struct is_compatible_string_type_impl < + BasicJsonType, CompatibleStringType, + enable_if_t<is_detected_exact<typename BasicJsonType::string_t::value_type, + value_type_t, CompatibleStringType>::value >> { static constexpr auto value = - std::is_same<typename RealType::value_type, typename CompatibleStringType::value_type>::value and - std::is_constructible<RealType, CompatibleStringType>::value; + std::is_constructible<typename BasicJsonType::string_t, CompatibleStringType>::value; }; -template<class BasicJsonType, class CompatibleStringType> +template <typename BasicJsonType, typename CompatibleStringType> struct is_compatible_string_type -{ - static auto constexpr value = is_compatible_string_type_impl < - conjunction<negation<std::is_same<void, CompatibleStringType>>, - is_detected<value_type_t, CompatibleStringType>>::value, - typename BasicJsonType::string_t, CompatibleStringType >::value; -}; + : is_compatible_string_type_impl<BasicJsonType, CompatibleStringType> {}; template<typename BasicJsonType, typename T> struct is_basic_json_nested_type