From 23bd2bce358230ea4d52aca35bbe328692256e83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20DELRIEU?= Date: Wed, 16 Nov 2016 20:49:24 +0100 Subject: [PATCH] add is_compatible_* traits --- src/json.hpp | 124 ++++++++++++++++++++++++++++++++++-------- test/src/unit-udt.cpp | 16 ++---- 2 files changed, 106 insertions(+), 34 deletions(-) diff --git a/src/json.hpp b/src/json.hpp index d8f33759..703a1e02 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -150,6 +150,96 @@ struct has_mapped_type std::is_integral()))>::value; }; +template +struct has_key_type +{ + private: + template + static int detect(U&&); + + static void detect(...); + public: + static constexpr bool value = + std::is_integral()))>::value; +}; + +template +struct has_value_type +{ + private: + template + static int detect(U&&); + + static void detect(...); + public: + static constexpr bool value = + std::is_integral()))>::value; +}; + +template +struct is_compatible_object_type_impl : std::false_type{}; + +template +struct is_compatible_object_type_impl +{ + static constexpr auto value = + std::is_constructible::value and + std::is_constructible::value; +}; + +template::value and has_key_type::value>> +struct is_compatible_object_type +{ + static auto constexpr value = is_compatible_object_type_impl::value and has_key_type::value, RealType, CompatibleObjectType>::value; +}; + +template +struct is_compatible_array_type_impl : std::false_type{}; + +template +struct is_compatible_array_type_impl +{ + static constexpr auto value = + not std::is_same::value and + not std::is_same::value and + not std::is_same::value and + not std::is_same::value and + not std::is_same::value and + not std::is_same::value and + std::is_constructible::value; + +}; + +template +struct is_compatible_array_type +{ + static auto constexpr value = is_compatible_array_type_impl::value, BasicJson, CompatibleArrayType>::value; +}; + +template +struct is_compatible_integer_type +{ + static constexpr auto value = + std::is_constructible::value and + std::numeric_limits::is_integer and + std::numeric_limits::is_signed; +}; + +template +struct is_compatible_unsigned_integer_type +{ + static constexpr auto value = std::is_constructible::value and + std::numeric_limits::is_integer and + not std::numeric_limits::is_signed; +}; + +template +struct is_compatible_float_type +{ + static constexpr auto value = std::is_constructible::value and + std::is_floating_point::value; +}; + template