diff --git a/src/json.hpp b/src/json.hpp index 096aecc8..ff58df20 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -119,6 +119,9 @@ using remove_reference_t = typename std::remove_reference::type; template using uncvref_t = remove_cv_t>; +template +using conditional_t = typename std::conditional::type; + // TODO update this doc /*! @brief unnamed namespace with internal helper functions @@ -127,6 +130,23 @@ using uncvref_t = remove_cv_t>; namespace detail { +// implementation of 3 C++17 constructs: conjunction, disjunction, negation. +// This is needed to avoid evaluating all the traits, MSVC cannot compile due +// to std::is_constructible being instantiated +// (void -> back_insert_iterator::value_type) +// this could slow down compilation, since this implementation is taken from the example in cppreference... +template struct conjunction : std::true_type {}; +template struct conjunction : B1 {}; +template +struct conjunction + : conditional_t, B1> {}; +template struct negation : std::integral_constant {}; +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. @@ -206,7 +226,12 @@ struct is_compatible_object_type_impl template struct is_compatible_object_type { - static auto constexpr value = is_compatible_object_type_impl::value and has_key_type::value, RealType, CompatibleObjectType>::value; + static auto constexpr value = is_compatible_object_type_impl< + conjunction>, + has_mapped_type, + has_key_type>::value, + RealType, CompatibleObjectType>::value; + }; template @@ -216,20 +241,25 @@ 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; + conjunction< + negation, + std::is_same, + std::is_same, + std::is_same, + std::is_same, + std::is_same>>, + std::is_constructible>::value; }; template struct is_compatible_array_type { - static auto constexpr value = is_compatible_array_type_impl::value and has_value_type::value and has_iterator::value, BasicJson, CompatibleArrayType>::value; + static auto constexpr value = is_compatible_array_type_impl< + conjunction>, + has_value_type, + has_iterator>::value, BasicJson, CompatibleArrayType>::value; }; template