20#include <nlohmann/detail/abi_macros.hpp>
21#include <nlohmann/detail/meta/type_traits.hpp>
22#include <nlohmann/detail/string_utils.hpp>
23#include <nlohmann/detail/value_t.hpp>
25NLOHMANN_JSON_NAMESPACE_BEGIN
29template<
typename IteratorType>
class iteration_proxy_value
32 using difference_type = std::ptrdiff_t;
33 using value_type = iteration_proxy_value;
34 using pointer = value_type *;
35 using reference = value_type &;
36 using iterator_category = std::forward_iterator_tag;
37 using string_type =
typename std::remove_cv< typename std::remove_reference<decltype( std::declval<IteratorType>().key() ) >::type >::type;
41 IteratorType anchor{};
43 std::size_t array_index = 0;
45 mutable std::size_t array_index_last = 0;
47 mutable string_type array_index_str =
"0";
49 string_type empty_str{};
52 explicit iteration_proxy_value() =
default;
53 explicit iteration_proxy_value(IteratorType it, std::size_t array_index_ = 0)
54 noexcept(std::is_nothrow_move_constructible<IteratorType>::value
55 && std::is_nothrow_default_constructible<string_type>::value)
56 : anchor(std::move(it))
57 , array_index(array_index_)
60 iteration_proxy_value(iteration_proxy_value
const&) =
default;
61 iteration_proxy_value& operator=(iteration_proxy_value
const&) =
default;
63 iteration_proxy_value(iteration_proxy_value&&)
64 noexcept(std::is_nothrow_move_constructible<IteratorType>::value
65 && std::is_nothrow_move_constructible<string_type>::value) =
default;
66 iteration_proxy_value& operator=(iteration_proxy_value&&)
67 noexcept(std::is_nothrow_move_assignable<IteratorType>::value
68 && std::is_nothrow_move_assignable<string_type>::value) =
default;
69 ~iteration_proxy_value() =
default;
97 return anchor == o.anchor;
103 return anchor != o.anchor;
107 const string_type&
key()
const
109 JSON_ASSERT(anchor.m_object !=
nullptr);
111 switch (anchor.m_object->type())
116 if (array_index != array_index_last)
118 int_to_string( array_index_str, array_index );
119 array_index_last = array_index;
121 return array_index_str;
143 typename IteratorType::reference
value()
const
145 return anchor.value();
150template<
typename IteratorType>
class iteration_proxy
154 typename IteratorType::pointer container =
nullptr;
157 explicit iteration_proxy() =
default;
161 : container(&cont) {}
185template<std::
size_t N,
typename IteratorType, enable_if_t<N == 0,
int> = 0>
186auto get(
const nlohmann::detail::iteration_proxy_value<IteratorType>& i) ->
decltype(i.key())
193template<std::
size_t N,
typename IteratorType, enable_if_t<N == 1,
int> = 0>
194auto get(
const nlohmann::detail::iteration_proxy_value<IteratorType>& i) ->
decltype(i.value())
200NLOHMANN_JSON_NAMESPACE_END
209#if defined(__clang__)
211 #pragma clang diagnostic push
212 #pragma clang diagnostic ignored "-Wmismatched-tags"
214template<
typename IteratorType>
215class tuple_size<::nlohmann::detail::iteration_proxy_value<IteratorType>>
216 :
public std::integral_constant<std::size_t, 2> {};
218template<std::
size_t N,
typename IteratorType>
219class tuple_element<N, ::nlohmann::detail::iteration_proxy_value<IteratorType >>
222 using type =
decltype(
223 get<N>(std::declval <
224 ::nlohmann::detail::iteration_proxy_value<IteratorType >> ()));
226#if defined(__clang__)
227 #pragma clang diagnostic pop
233 template <
typename IteratorType>
234 inline constexpr bool ::std::ranges::enable_borrowed_range<::nlohmann::detail::iteration_proxy<IteratorType>> =
true;
定义 iteration_proxy.hpp:30
IteratorType::reference value() const
return value of the iterator
定义 iteration_proxy.hpp:143
iteration_proxy_value & operator++()
increment operator (needed for range-based for)
定义 iteration_proxy.hpp:78
const iteration_proxy_value & operator*() const
dereference operator (needed for range-based for)
定义 iteration_proxy.hpp:72
bool operator!=(const iteration_proxy_value &o) const
inequality operator (needed for range-based for)
定义 iteration_proxy.hpp:101
bool operator==(const iteration_proxy_value &o) const
equality operator (needed for InputIterator)
定义 iteration_proxy.hpp:95
const string_type & key() const
return key of the iterator
定义 iteration_proxy.hpp:107
proxy class for the items() function
定义 iteration_proxy.hpp:151
iteration_proxy_value< IteratorType > begin() const noexcept
return iterator begin (needed for range-based for)
定义 iteration_proxy.hpp:170
iteration_proxy(typename IteratorType::reference cont) noexcept
construct iteration proxy from a container
定义 iteration_proxy.hpp:160
iteration_proxy_value< IteratorType > end() const noexcept
return iterator end (needed for range-based for)
定义 iteration_proxy.hpp:176
detail namespace with internal helper functions
定义 from_json.hpp:43
@ null
null value
定义 value_t.hpp:55
@ number_integer
number value (signed integer)
定义 value_t.hpp:60
@ boolean
boolean value
定义 value_t.hpp:59
@ discarded
discarded by the parser callback function
定义 value_t.hpp:64
@ binary
binary array (ordered collection of bytes)
定义 value_t.hpp:63
@ object
object (unordered set of name/value pairs)
定义 value_t.hpp:56
@ string
string value
定义 value_t.hpp:58
@ number_float
number value (floating-point)
定义 value_t.hpp:62
@ number_unsigned
number value (unsigned integer)
定义 value_t.hpp:61
@ array
array (ordered collection of values)
定义 value_t.hpp:57