diff options
Diffstat (limited to 'include/lib/modernjson/detail/conversions')
3 files changed, 42 insertions, 43 deletions
diff --git a/include/lib/modernjson/detail/conversions/from_json.hpp b/include/lib/modernjson/detail/conversions/from_json.hpp index 8281dda..817d4b7 100644 --- a/include/lib/modernjson/detail/conversions/from_json.hpp +++ b/include/lib/modernjson/detail/conversions/from_json.hpp @@ -84,13 +84,13 @@ void from_json(const BasicJsonType& j, typename BasicJsonType::string_t& s) } template < - typename BasicJsonType, typename CompatibleStringType, + typename BasicJsonType, typename ConstructibleStringType, enable_if_t < - is_compatible_string_type<BasicJsonType, CompatibleStringType>::value and + is_constructible_string_type<BasicJsonType, ConstructibleStringType>::value and not std::is_same<typename BasicJsonType::string_t, - CompatibleStringType>::value, + ConstructibleStringType>::value, int > = 0 > -void from_json(const BasicJsonType& j, CompatibleStringType& s) +void from_json(const BasicJsonType& j, ConstructibleStringType& s) { if (JSON_UNLIKELY(not j.is_string())) { @@ -173,11 +173,11 @@ auto from_json_array_impl(const BasicJsonType& j, std::array<T, N>& arr, } } -template<typename BasicJsonType, typename CompatibleArrayType> -auto from_json_array_impl(const BasicJsonType& j, CompatibleArrayType& arr, priority_tag<1> /*unused*/) +template<typename BasicJsonType, typename ConstructibleArrayType> +auto from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr, priority_tag<1> /*unused*/) -> decltype( - arr.reserve(std::declval<typename CompatibleArrayType::size_type>()), - j.template get<typename CompatibleArrayType::value_type>(), + arr.reserve(std::declval<typename ConstructibleArrayType::size_type>()), + j.template get<typename ConstructibleArrayType::value_type>(), void()) { using std::end; @@ -188,12 +188,12 @@ auto from_json_array_impl(const BasicJsonType& j, CompatibleArrayType& arr, prio { // get<BasicJsonType>() returns *this, this won't call a from_json // method when value_type is BasicJsonType - return i.template get<typename CompatibleArrayType::value_type>(); + return i.template get<typename ConstructibleArrayType::value_type>(); }); } -template <typename BasicJsonType, typename CompatibleArrayType> -void from_json_array_impl(const BasicJsonType& j, CompatibleArrayType& arr, +template <typename BasicJsonType, typename ConstructibleArrayType> +void from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr, priority_tag<0> /*unused*/) { using std::end; @@ -204,21 +204,21 @@ void from_json_array_impl(const BasicJsonType& j, CompatibleArrayType& arr, { // get<BasicJsonType>() returns *this, this won't call a from_json // method when value_type is BasicJsonType - return i.template get<typename CompatibleArrayType::value_type>(); + return i.template get<typename ConstructibleArrayType::value_type>(); }); } -template <typename BasicJsonType, typename CompatibleArrayType, +template <typename BasicJsonType, typename ConstructibleArrayType, enable_if_t < - is_compatible_array_type<BasicJsonType, CompatibleArrayType>::value and - not is_compatible_object_type<BasicJsonType, CompatibleArrayType>::value and - not is_compatible_string_type<BasicJsonType, CompatibleArrayType>::value and - not is_basic_json<CompatibleArrayType>::value, + is_constructible_array_type<BasicJsonType, ConstructibleArrayType>::value and + not is_constructible_object_type<BasicJsonType, ConstructibleArrayType>::value and + not is_constructible_string_type<BasicJsonType, ConstructibleArrayType>::value and + not is_basic_json<ConstructibleArrayType>::value, int > = 0 > -auto from_json(const BasicJsonType& j, CompatibleArrayType& arr) +auto from_json(const BasicJsonType& j, ConstructibleArrayType& arr) -> decltype(from_json_array_impl(j, arr, priority_tag<3> {}), -j.template get<typename CompatibleArrayType::value_type>(), +j.template get<typename ConstructibleArrayType::value_type>(), void()) { if (JSON_UNLIKELY(not j.is_array())) @@ -230,9 +230,9 @@ void()) from_json_array_impl(j, arr, priority_tag<3> {}); } -template<typename BasicJsonType, typename CompatibleObjectType, - enable_if_t<is_compatible_object_type<BasicJsonType, CompatibleObjectType>::value, int> = 0> -void from_json(const BasicJsonType& j, CompatibleObjectType& obj) +template<typename BasicJsonType, typename ConstructibleObjectType, + enable_if_t<is_constructible_object_type<BasicJsonType, ConstructibleObjectType>::value, int> = 0> +void from_json(const BasicJsonType& j, ConstructibleObjectType& obj) { if (JSON_UNLIKELY(not j.is_object())) { @@ -240,13 +240,13 @@ void from_json(const BasicJsonType& j, CompatibleObjectType& obj) } auto inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>(); - using value_type = typename CompatibleObjectType::value_type; + using value_type = typename ConstructibleObjectType::value_type; std::transform( inner_object->begin(), inner_object->end(), std::inserter(obj, obj.begin()), [](typename BasicJsonType::object_t::value_type const & p) { - return value_type(p.first, p.second.template get<typename CompatibleObjectType::mapped_type>()); + return value_type(p.first, p.second.template get<typename ConstructibleObjectType::mapped_type>()); }); } @@ -299,7 +299,7 @@ void from_json(const BasicJsonType& j, std::pair<A1, A2>& p) } template<typename BasicJsonType, typename Tuple, std::size_t... Idx> -void from_json_tuple_impl(const BasicJsonType& j, Tuple& t, index_sequence<Idx...>) +void from_json_tuple_impl(const BasicJsonType& j, Tuple& t, index_sequence<Idx...> /*unused*/) { t = std::make_tuple(j.at(Idx).template get<typename std::tuple_element<Idx, Tuple>::type>()...); } @@ -358,7 +358,7 @@ struct from_json_fn return from_json(j, val); } }; -} +} // namespace detail /// namespace to hold default `from_json` function /// to see why this is required: @@ -366,5 +366,5 @@ struct from_json_fn namespace { constexpr const auto& from_json = detail::static_const<detail::from_json_fn>::value; -} -} +} // namespace +} // namespace nlohmann diff --git a/include/lib/modernjson/detail/conversions/to_chars.hpp b/include/lib/modernjson/detail/conversions/to_chars.hpp index a13d258..b32e176 100644 --- a/include/lib/modernjson/detail/conversions/to_chars.hpp +++ b/include/lib/modernjson/detail/conversions/to_chars.hpp @@ -47,10 +47,9 @@ struct diyfp // f * 2^e { static constexpr int kPrecision = 64; // = q - uint64_t f; - int e; + uint64_t f = 0; + int e = 0; - constexpr diyfp() noexcept : f(0), e(0) {} constexpr diyfp(uint64_t f_, int e_) noexcept : f(f_), e(e_) {} /*! @@ -62,7 +61,7 @@ struct diyfp // f * 2^e assert(x.e == y.e); assert(x.f >= y.f); - return diyfp(x.f - y.f, x.e); + return {x.f - y.f, x.e}; } /*! @@ -127,7 +126,7 @@ struct diyfp // f * 2^e const uint64_t h = p3 + p2_hi + p1_hi + (Q >> 32); - return diyfp(h, x.e + y.e + 64); + return {h, x.e + y.e + 64}; } /*! @@ -158,7 +157,7 @@ struct diyfp // f * 2^e assert(delta >= 0); assert(((x.f << delta) >> delta) == x.f); - return diyfp(x.f << delta, target_exponent); + return {x.f << delta, target_exponent}; } }; @@ -461,7 +460,7 @@ inline cached_power get_cached_power_for_binary_exponent(int e) assert(e >= -1500); assert(e <= 1500); const int f = kAlpha - e - 1; - const int k = (f * 78913) / (1 << 18) + (f > 0); + const int k = (f * 78913) / (1 << 18) + static_cast<int>(f > 0); const int index = (-kCachedPowersMinDecExp + k + (kCachedPowersDecStep - 1)) / kCachedPowersDecStep; assert(index >= 0); @@ -609,7 +608,7 @@ inline void grisu2_digit_gen(char* buffer, int& length, int& decimal_exponent, const diyfp one(uint64_t{1} << -M_plus.e, M_plus.e); - uint32_t p1 = static_cast<uint32_t>(M_plus.f >> -one.e); // p1 = f div 2^-e (Since -e >= 32, p1 fits into a 32-bit int.) + auto p1 = static_cast<uint32_t>(M_plus.f >> -one.e); // p1 = f div 2^-e (Since -e >= 32, p1 fits into a 32-bit int.) uint64_t p2 = M_plus.f & (one.f - 1); // p2 = f mod 2^-e // 1) @@ -928,7 +927,7 @@ inline char* append_exponent(char* buf, int e) *buf++ = '+'; } - uint32_t k = static_cast<uint32_t>(e); + auto k = static_cast<uint32_t>(e); if (k < 10) { // Always print at least two digits in the exponent. @@ -1046,7 +1045,7 @@ format. Returns an iterator pointing past-the-end of the decimal representation. @note The result is NOT null-terminated. */ template <typename FloatType> -char* to_chars(char* first, char* last, FloatType value) +char* to_chars(char* first, const char* last, FloatType value) { static_cast<void>(last); // maybe unused - fix warning assert(std::isfinite(value)); diff --git a/include/lib/modernjson/detail/conversions/to_json.hpp b/include/lib/modernjson/detail/conversions/to_json.hpp index 37210ad..5c3669c 100644 --- a/include/lib/modernjson/detail/conversions/to_json.hpp +++ b/include/lib/modernjson/detail/conversions/to_json.hpp @@ -306,13 +306,13 @@ void to_json(BasicJsonType& j, const std::pair<Args...>& p) // for https://github.com/nlohmann/json/pull/1134 template<typename BasicJsonType, typename T, enable_if_t<std::is_same<T, typename iteration_proxy<typename BasicJsonType::iterator>::iteration_proxy_internal>::value, int> = 0> -void to_json(BasicJsonType& j, T b) noexcept +void to_json(BasicJsonType& j, const T& b) { j = {{b.key(), b.value()}}; } template<typename BasicJsonType, typename Tuple, std::size_t... Idx> -void to_json_tuple_impl(BasicJsonType& j, const Tuple& t, index_sequence<Idx...>) +void to_json_tuple_impl(BasicJsonType& j, const Tuple& t, index_sequence<Idx...> /*unused*/) { j = {std::get<Idx>(t)...}; } @@ -332,11 +332,11 @@ struct to_json_fn return to_json(j, std::forward<T>(val)); } }; -} +} // namespace detail /// namespace to hold default `to_json` function namespace { constexpr const auto& to_json = detail::static_const<detail::to_json_fn>::value; -} -} +} // namespace +} // namespace nlohmann |