Merge branches 'develop' and 'feature/optional' of https://github.com/nlohmann/json into feature/optional

This commit is contained in:
Niels Lohmann committed 2020-05-20 19:00:49 +02:00
commit b61d563ebe
89 files changed
+1718 -879

No files matched your search

@@ -2,7 +2,6 @@
#include <algorithm> // transform
#include <array> // array
#include <ciso646> // and, not
#include <forward_list> // forward_list
#include <iterator> // inserter, front_inserter, end
#include <map> // map
@@ -13,6 +12,7 @@
#include <utility> // pair, declval
#include <valarray> // valarray
#include <nlohmann/detail/boolean_operators.hpp>
#include <nlohmann/detail/exceptions.hpp>
#include <nlohmann/detail/macro_scope.hpp>
#include <nlohmann/detail/meta/cpp_future.hpp>
@@ -243,9 +243,9 @@ template <typename BasicJsonType, typename ConstructibleArrayType,
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 std::is_same<ConstructibleArrayType, typename BasicJsonType::binary_t>::value and
not is_basic_json<ConstructibleArrayType>::value,
int > = 0 >
auto from_json(const BasicJsonType& j, ConstructibleArrayType& arr)
-> decltype(from_json_array_impl(j, arr, priority_tag<3> {}),
j.template get<typename ConstructibleArrayType::value_type>(),
@@ -260,6 +260,17 @@ void())
from_json_array_impl(j, arr, priority_tag<3> {});
}
template <typename BasicJsonType>
void from_json(const BasicJsonType& j, typename BasicJsonType::binary_t& bin)
{
if (JSON_HEDLEY_UNLIKELY(not j.is_binary()))
{
JSON_THROW(type_error::create(302, "type must be binary, but is " + std::string(j.type_name())));
}
bin = *j.template get_ptr<const typename BasicJsonType::binary_t*>();
}
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)
@@ -2,12 +2,13 @@
#include <array> // array
#include <cassert> // assert
#include <ciso646> // or, and, not
#include <cmath> // signbit, isfinite
#include <cstdint> // intN_t, uintN_t
#include <cstring> // memcpy, memmove
#include <limits> // numeric_limits
#include <type_traits> // conditional
#include <nlohmann/detail/boolean_operators.hpp>
#include <nlohmann/detail/macro_scope.hpp>
namespace nlohmann
@@ -1,7 +1,6 @@
#pragma once
#include <algorithm> // copy
#include <ciso646> // or, and, not
#include <iterator> // begin, end
#include <string> // string
#include <tuple> // tuple, get
@@ -10,6 +9,7 @@
#include <valarray> // valarray
#include <vector> // vector
#include <nlohmann/detail/boolean_operators.hpp>
#include <nlohmann/detail/iterators/iteration_proxy.hpp>
#include <nlohmann/detail/meta/cpp_future.hpp>
#include <nlohmann/detail/meta/type_traits.hpp>
@@ -74,7 +74,7 @@ struct external_constructor<value_t::binary>
static void construct(BasicJsonType& j, const typename BasicJsonType::binary_t& b)
{
j.m_type = value_t::binary;
typename BasicJsonType::internal_binary_t value{b};
typename BasicJsonType::binary_t value{b};
j.m_value = value;
j.assert_invariant();
}
@@ -83,7 +83,7 @@ struct external_constructor<value_t::binary>
static void construct(BasicJsonType& j, typename BasicJsonType::binary_t&& b)
{
j.m_type = value_t::binary;
typename BasicJsonType::internal_binary_t value{std::move(b)};
typename BasicJsonType::binary_t value{std::move(b)};
j.m_value = value;
j.assert_invariant();
}
@@ -294,9 +294,9 @@ void to_json(BasicJsonType& j, const std::vector<bool>& e)
template <typename BasicJsonType, typename CompatibleArrayType,
enable_if_t<is_compatible_array_type<BasicJsonType,
CompatibleArrayType>::value and
not is_compatible_object_type<
BasicJsonType, CompatibleArrayType>::value and
not is_compatible_object_type<BasicJsonType, CompatibleArrayType>::value and
not is_compatible_string_type<BasicJsonType, CompatibleArrayType>::value and
not std::is_same<typename BasicJsonType::binary_t, CompatibleArrayType>::value and
not is_basic_json<CompatibleArrayType>::value,
int> = 0>
void to_json(BasicJsonType& j, const CompatibleArrayType& arr)
@@ -304,6 +304,12 @@ void to_json(BasicJsonType& j, const CompatibleArrayType& arr)
external_constructor<value_t::array>::construct(j, arr);
}
template <typename BasicJsonType>
void to_json(BasicJsonType& j, const typename BasicJsonType::binary_t& bin)
{
external_constructor<value_t::binary>::construct(j, bin);
}
template<typename BasicJsonType, typename T,
enable_if_t<std::is_convertible<T, BasicJsonType>::value, int> = 0>
void to_json(BasicJsonType& j, const std::valarray<T>& arr)