From 317883b21b086213a2f53727aca55d8c5a9b4d38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20DELRIEU?= Date: Sun, 8 Jan 2017 17:30:01 +0100 Subject: [PATCH] cleanup, details in body removes: - is_basic_json_compatible_type traits - a useless operator= - void_t - disjunction changes: - is_compatible_object_type's first argument is BasicJson --- src/json.hpp | 56 ++++++++++------------------------------------- src/json.hpp.re2c | 56 ++++++++++------------------------------------- 2 files changed, 22 insertions(+), 90 deletions(-) diff --git a/src/json.hpp b/src/json.hpp index c50212c1..721a6c48 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -326,15 +326,7 @@ struct external_constructor } }; -// very useful construct against boilerplate (more boilerplate needed than in -// C++17: http://en.cppreference.com/w/cpp/types/void_t) -template struct make_void -{ - using type = void; -}; -template using void_t = typename make_void::type; - -// Implementation of 3 C++17 constructs: conjunction, disjunction, negation. +// Implementation of 2 C++17 constructs: conjunction, negation. // This is needed to avoid evaluating all the traits in a condition // // For example: not std::is_same::value and has_value_type::value @@ -352,11 +344,6 @@ struct conjunction : conditional_t, B1> {}; template struct negation : std::integral_constant < bool, !B::value > {}; -template struct disjunction : std::false_type {}; -template struct disjunction : B1 {}; -template -struct disjunction -: conditional_t> {}; /*! @brief Helper to determine whether there's a key_type for T. @@ -399,16 +386,16 @@ struct is_compatible_object_type_impl typename CompatibleObjectType::mapped_type>::value; }; -template +template struct is_compatible_object_type { // As noted ahead, we need to stop evaluating traits if // `CompatibleObjectType = void`, hence the conjunction - static auto constexpr value = is_compatible_object_type_impl < - conjunction>, - has_mapped_type, - has_key_type>::value, - RealType, CompatibleObjectType >::value; + static auto constexpr value = is_compatible_object_type_impl< + conjunction>, + has_mapped_type, + has_key_type>::value, + typename BasicJson::object_t, CompatibleObjectType>::value; }; template @@ -439,7 +426,7 @@ struct is_compatible_array_type // `is_compatible_object_type`, but we need the conjunction here as well static auto constexpr value = is_compatible_array_type_impl< conjunction>, + BasicJson, CompatibleArrayType>>, negation>, has_value_type, @@ -482,12 +469,6 @@ struct is_compatible_float_type std::is_floating_point::value; }; -template -struct is_compatible_basic_json_type -{ - static auto constexpr value = false; -}; - template struct is_basic_json_nested_class { @@ -639,7 +620,7 @@ void to_json(Json &j, CompatibleArrayType const &arr) template < typename Json, typename CompatibleObjectType, - enable_if_t::value, + enable_if_t::value, int> = 0> void to_json(Json &j, CompatibleObjectType const &arr) { @@ -745,7 +726,7 @@ void from_json(Json const &j, CompatibleArrayType &arr) template < typename Json, typename CompatibleObjectType, - enable_if_t::value, + enable_if_t::value, int> = 0> void from_json(Json const &j, CompatibleObjectType &obj) { @@ -1863,7 +1844,6 @@ class basic_json // constructor chosen when: // - JSONSerializer::to_json exists for type T // - T is not a istream, nor convertible to basic_json (float, vectors, etc) - // is_compatible_basic_json_type == not is_user_defined_type template < typename T, enable_if_t>::value and @@ -1871,10 +1851,8 @@ class basic_json not std::is_same, basic_json_t>::value and not std::is_same, typename basic_json_t::array_t::iterator>::value and not std::is_same, typename basic_json_t::object_t::iterator>::value and - detail::conjunction, basic_json_t>>, detail::has_to_json>>::value, + uncvref_t>::value, int> = 0 > basic_json(T && val) { @@ -2428,18 +2406,6 @@ class basic_json return *this; } - // this overload is needed, since constructor for udt is explicit - template , basic_json_t>::value and - detail::has_to_json>::value>> - reference& operator=(T&& val) noexcept(std::is_nothrow_constructible>::value and - std::is_nothrow_move_assignable>::value) - { - static_assert(sizeof(T) == 0 , ""); - // I'm not sure this a is good practice... - return *this = basic_json_t{std::forward(val)}; - } - /*! @brief destructor diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c index f83ca76b..cc89accf 100644 --- a/src/json.hpp.re2c +++ b/src/json.hpp.re2c @@ -326,15 +326,7 @@ struct external_constructor } }; -// very useful construct against boilerplate (more boilerplate needed than in -// C++17: http://en.cppreference.com/w/cpp/types/void_t) -template struct make_void -{ - using type = void; -}; -template using void_t = typename make_void::type; - -// Implementation of 3 C++17 constructs: conjunction, disjunction, negation. +// Implementation of 2 C++17 constructs: conjunction, negation. // This is needed to avoid evaluating all the traits in a condition // // For example: not std::is_same::value and has_value_type::value @@ -352,11 +344,6 @@ struct conjunction : conditional_t, B1> {}; template struct negation : std::integral_constant < bool, !B::value > {}; -template struct disjunction : std::false_type {}; -template struct disjunction : B1 {}; -template -struct disjunction -: conditional_t> {}; /*! @brief Helper to determine whether there's a key_type for T. @@ -399,16 +386,16 @@ struct is_compatible_object_type_impl typename CompatibleObjectType::mapped_type>::value; }; -template +template struct is_compatible_object_type { // As noted ahead, we need to stop evaluating traits if // `CompatibleObjectType = void`, hence the conjunction - static auto constexpr value = is_compatible_object_type_impl < - conjunction>, - has_mapped_type, - has_key_type>::value, - RealType, CompatibleObjectType >::value; + static auto constexpr value = is_compatible_object_type_impl< + conjunction>, + has_mapped_type, + has_key_type>::value, + typename BasicJson::object_t, CompatibleObjectType>::value; }; template @@ -439,7 +426,7 @@ struct is_compatible_array_type // `is_compatible_object_type`, but we need the conjunction here as well static auto constexpr value = is_compatible_array_type_impl< conjunction>, + BasicJson, CompatibleArrayType>>, negation>, has_value_type, @@ -482,12 +469,6 @@ struct is_compatible_float_type std::is_floating_point::value; }; -template -struct is_compatible_basic_json_type -{ - static auto constexpr value = false; -}; - template struct is_basic_json_nested_class { @@ -639,7 +620,7 @@ void to_json(Json &j, CompatibleArrayType const &arr) template < typename Json, typename CompatibleObjectType, - enable_if_t::value, + enable_if_t::value, int> = 0> void to_json(Json &j, CompatibleObjectType const &arr) { @@ -745,7 +726,7 @@ void from_json(Json const &j, CompatibleArrayType &arr) template < typename Json, typename CompatibleObjectType, - enable_if_t::value, + enable_if_t::value, int> = 0> void from_json(Json const &j, CompatibleObjectType &obj) { @@ -1863,7 +1844,6 @@ class basic_json // constructor chosen when: // - JSONSerializer::to_json exists for type T // - T is not a istream, nor convertible to basic_json (float, vectors, etc) - // is_compatible_basic_json_type == not is_user_defined_type template < typename T, enable_if_t>::value and @@ -1871,10 +1851,8 @@ class basic_json not std::is_same, basic_json_t>::value and not std::is_same, typename basic_json_t::array_t::iterator>::value and not std::is_same, typename basic_json_t::object_t::iterator>::value and - detail::conjunction, basic_json_t>>, detail::has_to_json>>::value, + uncvref_t>::value, int> = 0 > basic_json(T && val) { @@ -2428,18 +2406,6 @@ class basic_json return *this; } - // this overload is needed, since constructor for udt is explicit - template , basic_json_t>::value and - detail::has_to_json>::value>> - reference& operator=(T&& val) noexcept(std::is_nothrow_constructible>::value and - std::is_nothrow_move_assignable>::value) - { - static_assert(sizeof(T) == 0 , ""); - // I'm not sure this a is good practice... - return *this = basic_json_t{std::forward(val)}; - } - /*! @brief destructor