#pragma once #include // not #include // size_t #include // numeric_limits #include // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type #include // declval #include #include namespace nlohmann { /*! @brief detail namespace with internal helper functions This namespace collects functions that should not be exposed, implementations of some @ref basic_json methods, and meta-programming helpers. @since version 2.1.0 */ namespace detail { ///////////// // helpers // ///////////// template struct is_basic_json : std::false_type {}; NLOHMANN_BASIC_JSON_TPL_DECLARATION struct is_basic_json : std::true_type {}; // alias templates to reduce boilerplate template using enable_if_t = typename std::enable_if::type; template using uncvref_t = typename std::remove_cv::type>::type; // implementation of C++14 index_sequence and affiliates // source: https://stackoverflow.com/a/32223343 template struct index_sequence { using type = index_sequence; using value_type = std::size_t; static constexpr std::size_t size() noexcept { return sizeof...(Ints); } }; template struct merge_and_renumber; template struct merge_and_renumber, index_sequence> : index_sequence < I1..., (sizeof...(I1) + I2)... > {}; template struct make_index_sequence : merge_and_renumber < typename make_index_sequence < N / 2 >::type, typename make_index_sequence < N - N / 2 >::type > {}; template<> struct make_index_sequence<0> : index_sequence<> {}; template<> struct make_index_sequence<1> : index_sequence<0> {}; template using index_sequence_for = make_index_sequence; /* Implementation of two 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 will not compile when T = void (on MSVC at least). Whereas conjunction>, has_value_type>::value will stop evaluating if negation<...>::value == false Please note that those constructs must be used with caution, since symbols can become very long quickly (which can slow down compilation and cause MSVC internal compiler errors). Only use it when you have to (see example ahead). */ template struct conjunction : std::true_type {}; template struct conjunction : B1 {}; template struct conjunction : std::conditional, B1>::type {}; template struct negation : std::integral_constant {}; // dispatch utility (taken from ranges-v3) template struct priority_tag : priority_tag < N - 1 > {}; template<> struct priority_tag<0> {}; //////////////////////// // has_/is_ functions // //////////////////////// // source: https://stackoverflow.com/a/37193089/4116453 template struct is_complete_type : std::false_type {}; template struct is_complete_type : std::true_type {}; NLOHMANN_JSON_HAS_HELPER(mapped_type); NLOHMANN_JSON_HAS_HELPER(key_type); NLOHMANN_JSON_HAS_HELPER(value_type); NLOHMANN_JSON_HAS_HELPER(iterator); 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 struct is_compatible_string_type_impl : std::false_type {}; template struct is_compatible_string_type_impl { static constexpr auto value = std::is_same::value; }; template struct is_compatible_object_type { static auto constexpr value = is_compatible_object_type_impl < conjunction>, has_mapped_type, has_key_type>::value, typename BasicJsonType::object_t, CompatibleObjectType >::value; }; template struct is_compatible_string_type { static auto constexpr value = is_compatible_string_type_impl < conjunction>, has_value_type>::value, typename BasicJsonType::string_t, CompatibleStringType >::value; }; template struct is_basic_json_nested_type { static auto constexpr value = std::is_same::value or std::is_same::value or std::is_same::value or std::is_same::value; }; template struct is_compatible_array_type { static auto constexpr value = conjunction>, negation>, negation>, negation>, has_value_type, has_iterator>::value; }; template struct is_compatible_integer_type_impl : std::false_type {}; template struct is_compatible_integer_type_impl { // 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 CompatibleLimits::is_integer and RealLimits::is_signed == CompatibleLimits::is_signed; }; 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; }; // trait checking if JSONSerializer::from_json(json const&, udt&) exists template struct has_from_json { private: // also check the return type of from_json template::from_json( std::declval(), std::declval()))>::value>> static int detect(U&&); static void detect(...); public: static constexpr bool value = std::is_integral>()))>::value; }; // This trait checks if JSONSerializer::from_json(json const&) exists // this overload is used for non-default-constructible user-defined-types template struct has_non_default_from_json { private: template < typename U, typename = enable_if_t::from_json(std::declval()))>::value >> static int detect(U&&); static void detect(...); public: static constexpr bool value = std::is_integral>()))>::value; }; // This trait checks if BasicJsonType::json_serializer::to_json exists template struct has_to_json { private: template::to_json( std::declval(), std::declval()))> static int detect(U&&); static void detect(...); public: static constexpr bool value = std::is_integral>()))>::value; }; template struct is_compatible_complete_type { static constexpr bool value = not std::is_base_of::value and not is_basic_json::value and not is_basic_json_nested_type::value and has_to_json::value; }; template struct is_compatible_type : conjunction, is_compatible_complete_type> { }; // taken from ranges-v3 template struct static_const { static constexpr T value{}; }; template constexpr T static_const::value; } }