mirror of
https://github.com/nlohmann/json.git
synced 2026-11-22 10:54:22 +00:00
Fix CI: build custom array types without a fill constructor, re-amalgamate
copy_array_level() built the destination array with the fill constructor array_t(count, value), which is not part of the array container interface the library otherwise assumes (e.g. custom ArrayTypes that only provide a default and an iterator-pair constructor, as covered by unit-custom-array-type.cpp). Default- construct the array and resize() it instead, matching how the rest of the codebase already grows array_t. Also re-run the amalgamation, which had fallen out of sync with include/nlohmann/json.hpp. Signed-off-by: Niels Lohmann <mail@nlohmann.me> Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1881df5e50
commit
aa3fadd4ad
2 files changed
+73
-65
No files matched your search
@@ -1078,8 +1078,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
const array_t& src_array = *src.m_data.m_value.array;
|
const array_t& src_array = *src.m_data.m_value.array;
|
||||||
|
|
||||||
// create all elements up front: growing the array afterwards could
|
// create all elements up front: growing the array afterwards could
|
||||||
// invalidate the pointers that are handed to the worklist
|
// invalidate the pointers that are handed to the worklist; resize()
|
||||||
dst.m_data.m_value.array = create<array_t>(src_array.size(), basic_json());
|
// rather than the fill constructor, because not every array type
|
||||||
|
// provides the latter (e.g., ones without a matching allocator-aware
|
||||||
|
// fill constructor)
|
||||||
|
dst.m_data.m_value.array = create<array_t>();
|
||||||
|
dst.m_data.m_value.array->resize(src_array.size());
|
||||||
|
|
||||||
auto dst_it = dst.m_data.m_value.array->begin();
|
auto dst_it = dst.m_data.m_value.array->begin();
|
||||||
for (auto src_it = src_array.cbegin(); src_it != src_array.cend(); ++src_it, ++dst_it)
|
for (auto src_it = src_array.cbegin(); src_it != src_array.cend(); ++src_it, ++dst_it)
|
||||||
|
|||||||
@@ -3833,71 +3833,71 @@ NLOHMANN_JSON_NAMESPACE_END
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
#ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_
|
#ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_
|
||||||
#define INCLUDE_NLOHMANN_JSON_FWD_HPP_
|
#define INCLUDE_NLOHMANN_JSON_FWD_HPP_
|
||||||
|
|
||||||
#include <cstdint> // int64_t, uint64_t
|
#include <cstdint> // int64_t, uint64_t
|
||||||
#include <map> // map
|
#include <map> // map
|
||||||
#include <memory> // allocator
|
#include <memory> // allocator
|
||||||
#include <string> // string
|
#include <string> // string
|
||||||
#include <vector> // vector
|
#include <vector> // vector
|
||||||
|
|
||||||
// #include <nlohmann/detail/abi_macros.hpp>
|
// #include <nlohmann/detail/abi_macros.hpp>
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief namespace for Niels Lohmann
|
@brief namespace for Niels Lohmann
|
||||||
@see https://github.com/nlohmann
|
@see https://github.com/nlohmann
|
||||||
@since version 1.0.0
|
@since version 1.0.0
|
||||||
*/
|
*/
|
||||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief default JSONSerializer template argument
|
@brief default JSONSerializer template argument
|
||||||
|
|
||||||
This serializer ignores the template arguments and uses ADL
|
This serializer ignores the template arguments and uses ADL
|
||||||
([argument-dependent lookup](https://en.cppreference.com/w/cpp/language/adl))
|
([argument-dependent lookup](https://en.cppreference.com/w/cpp/language/adl))
|
||||||
for serialization.
|
for serialization.
|
||||||
*/
|
*/
|
||||||
template<typename T = void, typename SFINAE = void>
|
template<typename T = void, typename SFINAE = void>
|
||||||
struct adl_serializer;
|
struct adl_serializer;
|
||||||
|
|
||||||
/// a class to store JSON values
|
/// a class to store JSON values
|
||||||
/// @sa https://json.nlohmann.me/api/basic_json/
|
/// @sa https://json.nlohmann.me/api/basic_json/
|
||||||
template<template<typename U, typename V, typename... Args> class ObjectType =
|
template<template<typename U, typename V, typename... Args> class ObjectType =
|
||||||
std::map,
|
std::map,
|
||||||
template<typename U, typename... Args> class ArrayType = std::vector,
|
template<typename U, typename... Args> class ArrayType = std::vector,
|
||||||
class StringType = std::string, class BooleanType = bool,
|
class StringType = std::string, class BooleanType = bool,
|
||||||
class NumberIntegerType = std::int64_t,
|
class NumberIntegerType = std::int64_t,
|
||||||
class NumberUnsignedType = std::uint64_t,
|
class NumberUnsignedType = std::uint64_t,
|
||||||
class NumberFloatType = double,
|
class NumberFloatType = double,
|
||||||
template<typename U> class AllocatorType = std::allocator,
|
template<typename U> class AllocatorType = std::allocator,
|
||||||
template<typename T, typename SFINAE = void> class JSONSerializer =
|
template<typename T, typename SFINAE = void> class JSONSerializer =
|
||||||
adl_serializer,
|
adl_serializer,
|
||||||
class BinaryType = std::vector<std::uint8_t>, // cppcheck-suppress syntaxError
|
class BinaryType = std::vector<std::uint8_t>, // cppcheck-suppress syntaxError
|
||||||
class CustomBaseClass = void>
|
class CustomBaseClass = void>
|
||||||
class basic_json;
|
class basic_json;
|
||||||
|
|
||||||
/// @brief JSON Pointer defines a string syntax for identifying a specific value within a JSON document
|
/// @brief JSON Pointer defines a string syntax for identifying a specific value within a JSON document
|
||||||
/// @sa https://json.nlohmann.me/api/json_pointer/
|
/// @sa https://json.nlohmann.me/api/json_pointer/
|
||||||
template<typename RefStringType>
|
template<typename RefStringType>
|
||||||
class json_pointer;
|
class json_pointer;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief default specialization
|
@brief default specialization
|
||||||
@sa https://json.nlohmann.me/api/json/
|
@sa https://json.nlohmann.me/api/json/
|
||||||
*/
|
*/
|
||||||
using json = basic_json<>;
|
using json = basic_json<>;
|
||||||
|
|
||||||
/// @brief a minimal map-like container that preserves insertion order
|
/// @brief a minimal map-like container that preserves insertion order
|
||||||
/// @sa https://json.nlohmann.me/api/ordered_map/
|
/// @sa https://json.nlohmann.me/api/ordered_map/
|
||||||
template<class Key, class T, class IgnoredLess, class Allocator>
|
template<class Key, class T, class IgnoredLess, class Allocator>
|
||||||
struct ordered_map;
|
struct ordered_map;
|
||||||
|
|
||||||
/// @brief specialization that maintains the insertion order of object keys
|
/// @brief specialization that maintains the insertion order of object keys
|
||||||
/// @sa https://json.nlohmann.me/api/ordered_json/
|
/// @sa https://json.nlohmann.me/api/ordered_json/
|
||||||
using ordered_json = basic_json<nlohmann::ordered_map>;
|
using ordered_json = basic_json<nlohmann::ordered_map>;
|
||||||
|
|
||||||
NLOHMANN_JSON_NAMESPACE_END
|
NLOHMANN_JSON_NAMESPACE_END
|
||||||
|
|
||||||
#endif // INCLUDE_NLOHMANN_JSON_FWD_HPP_
|
#endif // INCLUDE_NLOHMANN_JSON_FWD_HPP_
|
||||||
|
|
||||||
@@ -6016,7 +6016,7 @@ NLOHMANN_JSON_NAMESPACE_END
|
|||||||
|
|
||||||
|
|
||||||
// #include <nlohmann/detail/macro_scope.hpp>
|
// #include <nlohmann/detail/macro_scope.hpp>
|
||||||
// JSON_HAS_CPP_17
|
// JSON_HAS_CPP_17
|
||||||
#ifdef JSON_HAS_CPP_17
|
#ifdef JSON_HAS_CPP_17
|
||||||
#include <optional> // optional
|
#include <optional> // optional
|
||||||
#endif
|
#endif
|
||||||
@@ -24080,10 +24080,10 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
const bool ignore_comments = false,
|
const bool ignore_comments = false,
|
||||||
const bool ignore_trailing_commas = false,
|
const bool ignore_trailing_commas = false,
|
||||||
const bool discard_number_values = false
|
const bool discard_number_values = false
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return ::nlohmann::detail::parser<basic_json, InputAdapterType>(std::move(adapter),
|
return ::nlohmann::detail::parser<basic_json, InputAdapterType>(std::move(adapter),
|
||||||
std::move(cb), allow_exceptions, ignore_comments, ignore_trailing_commas, discard_number_values);
|
std::move(cb), allow_exceptions, ignore_comments, ignore_trailing_commas, discard_number_values);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -24992,8 +24992,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
const array_t& src_array = *src.m_data.m_value.array;
|
const array_t& src_array = *src.m_data.m_value.array;
|
||||||
|
|
||||||
// create all elements up front: growing the array afterwards could
|
// create all elements up front: growing the array afterwards could
|
||||||
// invalidate the pointers that are handed to the worklist
|
// invalidate the pointers that are handed to the worklist; resize()
|
||||||
dst.m_data.m_value.array = create<array_t>(src_array.size(), basic_json());
|
// rather than the fill constructor, because not every array type
|
||||||
|
// provides the latter (e.g., ones without a matching allocator-aware
|
||||||
|
// fill constructor)
|
||||||
|
dst.m_data.m_value.array = create<array_t>();
|
||||||
|
dst.m_data.m_value.array->resize(src_array.size());
|
||||||
|
|
||||||
auto dst_it = dst.m_data.m_value.array->begin();
|
auto dst_it = dst.m_data.m_value.array->begin();
|
||||||
for (auto src_it = src_array.cbegin(); src_it != src_array.cend(); ++src_it, ++dst_it)
|
for (auto src_it = src_array.cbegin(); src_it != src_array.cend(); ++src_it, ++dst_it)
|
||||||
@@ -25189,8 +25193,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
detail::enable_if_t <
|
detail::enable_if_t <
|
||||||
!detail::is_basic_json<U>::value && detail::is_compatible_type<basic_json_t, U>::value, int > = 0 >
|
!detail::is_basic_json<U>::value && detail::is_compatible_type<basic_json_t, U>::value, int > = 0 >
|
||||||
basic_json(CompatibleType && val) noexcept(noexcept( // NOLINT(bugprone-forwarding-reference-overload,bugprone-exception-escape)
|
basic_json(CompatibleType && val) noexcept(noexcept( // NOLINT(bugprone-forwarding-reference-overload,bugprone-exception-escape)
|
||||||
JSONSerializer<U>::to_json(std::declval<basic_json_t&>(),
|
JSONSerializer<U>::to_json(std::declval<basic_json_t&>(),
|
||||||
std::forward<CompatibleType>(val))))
|
std::forward<CompatibleType>(val))))
|
||||||
{
|
{
|
||||||
JSONSerializer<U>::to_json(*this, std::forward<CompatibleType>(val));
|
JSONSerializer<U>::to_json(*this, std::forward<CompatibleType>(val));
|
||||||
set_parents();
|
set_parents();
|
||||||
@@ -25967,7 +25971,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
detail::has_from_json<basic_json_t, ValueType>::value,
|
detail::has_from_json<basic_json_t, ValueType>::value,
|
||||||
int > = 0 >
|
int > = 0 >
|
||||||
ValueType get_impl(detail::priority_tag<0> /*unused*/) const noexcept(noexcept(
|
ValueType get_impl(detail::priority_tag<0> /*unused*/) const noexcept(noexcept(
|
||||||
JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), std::declval<ValueType&>())))
|
JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), std::declval<ValueType&>())))
|
||||||
{
|
{
|
||||||
auto ret = ValueType();
|
auto ret = ValueType();
|
||||||
JSONSerializer<ValueType>::from_json(*this, ret);
|
JSONSerializer<ValueType>::from_json(*this, ret);
|
||||||
@@ -26009,7 +26013,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
detail::has_non_default_from_json<basic_json_t, ValueType>::value,
|
detail::has_non_default_from_json<basic_json_t, ValueType>::value,
|
||||||
int > = 0 >
|
int > = 0 >
|
||||||
ValueType get_impl(detail::priority_tag<1> /*unused*/) const noexcept(noexcept(
|
ValueType get_impl(detail::priority_tag<1> /*unused*/) const noexcept(noexcept(
|
||||||
JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>())))
|
JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>())))
|
||||||
{
|
{
|
||||||
return JSONSerializer<ValueType>::from_json(*this);
|
return JSONSerializer<ValueType>::from_json(*this);
|
||||||
}
|
}
|
||||||
@@ -26159,7 +26163,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
|||||||
detail::has_from_json<basic_json_t, ValueType>::value,
|
detail::has_from_json<basic_json_t, ValueType>::value,
|
||||||
int > = 0 >
|
int > = 0 >
|
||||||
ValueType & get_to(ValueType& v) const noexcept(noexcept(
|
ValueType & get_to(ValueType& v) const noexcept(noexcept(
|
||||||
JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), v)))
|
JSONSerializer<ValueType>::from_json(std::declval<const basic_json_t&>(), v)))
|
||||||
{
|
{
|
||||||
JSONSerializer<ValueType>::from_json(*this, v);
|
JSONSerializer<ValueType>::from_json(*this, v);
|
||||||
return v;
|
return v;
|
||||||
|
|||||||
Reference in new issue
Block a user