mirror of
https://github.com/nlohmann/json.git
synced 2026-11-20 02:05:19 +00:00
Compare commits
6
Commits
abd3c275d1
...
3b632e489a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3b632e489a | ||
|
|
2852427b3f | ||
|
|
8085a8f5ec | ||
|
|
cf4e0164c4 | ||
|
|
3562da8556 | ||
|
|
e30d2aed18 |
No files matched your search
@@ -375,18 +375,18 @@ struct is_trivial_element
|
||||
|
||||
// the element type may not be default constructible: construct every element
|
||||
// in place (a pack expansion that is unrolled N times)
|
||||
template < typename BasicJsonType, typename T, std::size_t N >
|
||||
std::array<T, N> from_json_inplace_array(const BasicJsonType& j, identity_tag<std::array<T, N>> tag,
|
||||
std::false_type /*is_trivial_element*/)
|
||||
template<typename BasicJsonType, typename T, std::size_t N>
|
||||
std::array<T, N> from_json_make_array(const BasicJsonType& j, identity_tag<std::array<T, N>> tag,
|
||||
std::false_type /*is_trivial_element*/)
|
||||
{
|
||||
return from_json_inplace_array_impl(j, tag, make_index_sequence<N> {});
|
||||
}
|
||||
|
||||
// a trivial element type cannot tell default construction plus assignment from
|
||||
// construction in place, so use a loop instead of unrolling N conversions
|
||||
template < typename BasicJsonType, typename T, std::size_t N >
|
||||
std::array<T, N> from_json_inplace_array(const BasicJsonType& j, identity_tag<std::array<T, N>> /*unused*/,
|
||||
std::true_type /*is_trivial_element*/)
|
||||
template<typename BasicJsonType, typename T, std::size_t N>
|
||||
std::array<T, N> from_json_make_array(const BasicJsonType& j, identity_tag<std::array<T, N>> /*unused*/,
|
||||
std::true_type /*is_trivial_element*/)
|
||||
{
|
||||
std::array<T, N> arr; // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init): every element is assigned or an exception is thrown
|
||||
from_json_std_array(j, arr);
|
||||
@@ -402,7 +402,7 @@ auto from_json(const BasicJsonType& j, identity_tag<std::array<T, N>> tag)
|
||||
throw_type_must_be("array", j);
|
||||
}
|
||||
|
||||
return from_json_inplace_array(j, tag, is_trivial_element<T> {});
|
||||
return from_json_make_array(j, tag, is_trivial_element<T> {});
|
||||
}
|
||||
|
||||
template<typename BasicJsonType>
|
||||
|
||||
@@ -937,6 +937,8 @@ class json_sax_dom_parser : public json_sax_dom_error_state
|
||||
/// directly if the value was the one too many.
|
||||
void place_container(const frame& f, frame* enclosing, BasicJsonType&& value, const bool enclosing_is_innermost)
|
||||
{
|
||||
// only a container with a slot may have no enclosing container
|
||||
JSON_ASSERT(f.slot != nullptr || enclosing != nullptr);
|
||||
if (f.slot != nullptr)
|
||||
{
|
||||
*f.slot = std::move(value);
|
||||
|
||||
@@ -395,7 +395,7 @@ class basic_json_view
|
||||
{
|
||||
if (NLOHMANN_VIEW_UNLIKELY(!is_object()))
|
||||
{
|
||||
detail::view::throw_type_error(306, "cannot use value() with ", type_name());
|
||||
detail::view::throw_type_error(detail::exception_id::value_wrong_type, "cannot use value() with ", type_name());
|
||||
}
|
||||
// (the default is made only if there is no such member)
|
||||
const basic_json_view r = lookup(key);
|
||||
@@ -420,7 +420,7 @@ class basic_json_view
|
||||
{
|
||||
if (NLOHMANN_VIEW_UNLIKELY(!is_structured()))
|
||||
{
|
||||
detail::view::throw_type_error(306, "cannot use value() with ", type_name());
|
||||
detail::view::throw_type_error(detail::exception_id::value_wrong_type, "cannot use value() with ", type_name());
|
||||
}
|
||||
const basic_json_view r = detail::view::resolve_pointer(*this, detail::json_pointer_access::reference_tokens(ptr), detail::view::pointer_mode::value);
|
||||
return r.is_discarded() ? string_t(default_value) : r.template get<string_t>();
|
||||
|
||||
Generated
+9
-7
@@ -6399,18 +6399,18 @@ struct is_trivial_element
|
||||
|
||||
// the element type may not be default constructible: construct every element
|
||||
// in place (a pack expansion that is unrolled N times)
|
||||
template < typename BasicJsonType, typename T, std::size_t N >
|
||||
std::array<T, N> from_json_inplace_array(const BasicJsonType& j, identity_tag<std::array<T, N>> tag,
|
||||
std::false_type /*is_trivial_element*/)
|
||||
template<typename BasicJsonType, typename T, std::size_t N>
|
||||
std::array<T, N> from_json_make_array(const BasicJsonType& j, identity_tag<std::array<T, N>> tag,
|
||||
std::false_type /*is_trivial_element*/)
|
||||
{
|
||||
return from_json_inplace_array_impl(j, tag, make_index_sequence<N> {});
|
||||
}
|
||||
|
||||
// a trivial element type cannot tell default construction plus assignment from
|
||||
// construction in place, so use a loop instead of unrolling N conversions
|
||||
template < typename BasicJsonType, typename T, std::size_t N >
|
||||
std::array<T, N> from_json_inplace_array(const BasicJsonType& j, identity_tag<std::array<T, N>> /*unused*/,
|
||||
std::true_type /*is_trivial_element*/)
|
||||
template<typename BasicJsonType, typename T, std::size_t N>
|
||||
std::array<T, N> from_json_make_array(const BasicJsonType& j, identity_tag<std::array<T, N>> /*unused*/,
|
||||
std::true_type /*is_trivial_element*/)
|
||||
{
|
||||
std::array<T, N> arr; // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init): every element is assigned or an exception is thrown
|
||||
from_json_std_array(j, arr);
|
||||
@@ -6426,7 +6426,7 @@ auto from_json(const BasicJsonType& j, identity_tag<std::array<T, N>> tag)
|
||||
throw_type_must_be("array", j);
|
||||
}
|
||||
|
||||
return from_json_inplace_array(j, tag, is_trivial_element<T> {});
|
||||
return from_json_make_array(j, tag, is_trivial_element<T> {});
|
||||
}
|
||||
|
||||
template<typename BasicJsonType>
|
||||
@@ -16060,6 +16060,8 @@ class json_sax_dom_parser : public json_sax_dom_error_state
|
||||
/// directly if the value was the one too many.
|
||||
void place_container(const frame& f, frame* enclosing, BasicJsonType&& value, const bool enclosing_is_innermost)
|
||||
{
|
||||
// only a container with a slot may have no enclosing container
|
||||
JSON_ASSERT(f.slot != nullptr || enclosing != nullptr);
|
||||
if (f.slot != nullptr)
|
||||
{
|
||||
*f.slot = std::move(value);
|
||||
|
||||
Generated
+2
-2
@@ -8082,7 +8082,7 @@ class basic_json_view
|
||||
{
|
||||
if (NLOHMANN_VIEW_UNLIKELY(!is_object()))
|
||||
{
|
||||
detail::view::throw_type_error(306, "cannot use value() with ", type_name());
|
||||
detail::view::throw_type_error(detail::exception_id::value_wrong_type, "cannot use value() with ", type_name());
|
||||
}
|
||||
// (the default is made only if there is no such member)
|
||||
const basic_json_view r = lookup(key);
|
||||
@@ -8107,7 +8107,7 @@ class basic_json_view
|
||||
{
|
||||
if (NLOHMANN_VIEW_UNLIKELY(!is_structured()))
|
||||
{
|
||||
detail::view::throw_type_error(306, "cannot use value() with ", type_name());
|
||||
detail::view::throw_type_error(detail::exception_id::value_wrong_type, "cannot use value() with ", type_name());
|
||||
}
|
||||
const basic_json_view r = detail::view::resolve_pointer(*this, detail::json_pointer_access::reference_tokens(ptr), detail::view::pointer_mode::value);
|
||||
return r.is_discarded() ? string_t(default_value) : r.template get<string_t>();
|
||||
|
||||
Reference in new issue
Block a user