From 1542f34f0e0fc53324f6fdc5905f4b77b252a789 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Mon, 26 Nov 2018 09:06:31 +0100 Subject: update nlohmann modernjson to v3.4 (with bson support) --- .../modernjson/detail/conversions/from_json.hpp | 56 +++++++++++----------- .../lib/modernjson/detail/conversions/to_chars.hpp | 19 ++++---- .../lib/modernjson/detail/conversions/to_json.hpp | 10 ++-- 3 files changed, 42 insertions(+), 43 deletions(-) (limited to 'include/lib/modernjson/detail/conversions') 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::value and + is_constructible_string_type::value and not std::is_same::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& arr, } } -template -auto from_json_array_impl(const BasicJsonType& j, CompatibleArrayType& arr, priority_tag<1> /*unused*/) +template +auto from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr, priority_tag<1> /*unused*/) -> decltype( - arr.reserve(std::declval()), - j.template get(), + arr.reserve(std::declval()), + j.template get(), void()) { using std::end; @@ -188,12 +188,12 @@ auto from_json_array_impl(const BasicJsonType& j, CompatibleArrayType& arr, prio { // get() returns *this, this won't call a from_json // method when value_type is BasicJsonType - return i.template get(); + return i.template get(); }); } -template -void from_json_array_impl(const BasicJsonType& j, CompatibleArrayType& arr, +template +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() returns *this, this won't call a from_json // method when value_type is BasicJsonType - return i.template get(); + return i.template get(); }); } -template ::value and - not is_compatible_object_type::value and - not is_compatible_string_type::value and - not is_basic_json::value, + is_constructible_array_type::value and + not is_constructible_object_type::value and + not is_constructible_string_type::value and + not is_basic_json::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(), +j.template get(), void()) { if (JSON_UNLIKELY(not j.is_array())) @@ -230,9 +230,9 @@ void()) from_json_array_impl(j, arr, priority_tag<3> {}); } -template::value, int> = 0> -void from_json(const BasicJsonType& j, CompatibleObjectType& obj) +template::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(); - 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()); + return value_type(p.first, p.second.template get()); }); } @@ -299,7 +299,7 @@ void from_json(const BasicJsonType& j, std::pair& p) } template -void from_json_tuple_impl(const BasicJsonType& j, Tuple& t, index_sequence) +void from_json_tuple_impl(const BasicJsonType& j, Tuple& t, index_sequence /*unused*/) { t = std::make_tuple(j.at(Idx).template get::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::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(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(M_plus.f >> -one.e); // p1 = f div 2^-e (Since -e >= 32, p1 fits into a 32-bit int.) + auto p1 = static_cast(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(e); + auto k = static_cast(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 -char* to_chars(char* first, char* last, FloatType value) +char* to_chars(char* first, const char* last, FloatType value) { static_cast(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& p) // for https://github.com/nlohmann/json/pull/1134 template::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 -void to_json_tuple_impl(BasicJsonType& j, const Tuple& t, index_sequence) +void to_json_tuple_impl(BasicJsonType& j, const Tuple& t, index_sequence /*unused*/) { j = {std::get(t)...}; } @@ -332,11 +332,11 @@ struct to_json_fn return to_json(j, std::forward(val)); } }; -} +} // namespace detail /// namespace to hold default `to_json` function namespace { constexpr const auto& to_json = detail::static_const::value; -} -} +} // namespace +} // namespace nlohmann -- cgit v1.2.3