8 #include <nlohmann/detail/meta/type_traits.hpp>
9 #include <nlohmann/detail/value_t.hpp>
15 template<
typename string_type>
16 void int_to_string( string_type& target, std::size_t value )
18 target = std::to_string(value);
20 template <
typename IteratorType>
class iteration_proxy_value
23 using difference_type = std::ptrdiff_t;
24 using value_type = iteration_proxy_value;
25 using pointer = value_type * ;
26 using reference = value_type & ;
27 using iterator_category = std::input_iterator_tag;
28 using string_type =
typename std::remove_cv< typename std::remove_reference<decltype( std::declval<IteratorType>().key() ) >::type >::type;
34 std::size_t array_index = 0;
36 mutable std::size_t array_index_last = 0;
38 mutable string_type array_index_str =
"0";
40 const string_type empty_str =
"";
43 explicit iteration_proxy_value(IteratorType it) noexcept : anchor(it) {}
61 bool operator==(
const iteration_proxy_value& o)
const
63 return anchor == o.anchor;
67 bool operator!=(
const iteration_proxy_value& o)
const
69 return anchor != o.anchor;
73 const string_type&
key()
const
75 assert(anchor.m_object !=
nullptr);
77 switch (anchor.m_object->type())
82 if (array_index != array_index_last)
84 int_to_string( array_index_str, array_index );
85 array_index_last = array_index;
87 return array_index_str;
101 typename IteratorType::reference
value()
const
103 return anchor.value();
108 template<
typename IteratorType>
class iteration_proxy
112 typename IteratorType::reference container;
116 explicit iteration_proxy(
typename IteratorType::reference cont) noexcept
120 iteration_proxy_value<IteratorType>
begin() noexcept
122 return iteration_proxy_value<IteratorType>(container.begin());
126 iteration_proxy_value<IteratorType>
end() noexcept
128 return iteration_proxy_value<IteratorType>(container.end());
134 template <std::
size_t N,
typename IteratorType, enable_if_t<N == 0,
int> = 0>
142 template <std::
size_t N,
typename IteratorType, enable_if_t<N == 1,
int> = 0>
156 #if defined(__clang__)
158 #pragma clang diagnostic push
159 #pragma clang diagnostic ignored "-Wmismatched-tags"
161 template <
typename IteratorType>
163 :
public std::integral_constant<std::size_t, 2> {};
165 template <std::
size_t N,
typename IteratorType>
169 using type = decltype(
170 get<N>(std::declval <
173 #if defined(__clang__)
174 #pragma clang diagnostic pop