1
0
mirror of https://github.com/nlohmann/json.git synced 2025-07-28 12:02:00 +03:00

Merge pull request #1134 from Daniel599/feature/items_iterator

fixed compile error for #1045
This commit is contained in:
Niels Lohmann
2018-06-28 21:21:17 +02:00
committed by GitHub
4 changed files with 82 additions and 3 deletions

View File

@ -2,6 +2,7 @@
#include <cstddef> // size_t
#include <string> // string, to_string
#include <iterator> // input_iterator_tag
#include <nlohmann/detail/value_t.hpp>
@ -16,6 +17,13 @@ template<typename IteratorType> class iteration_proxy
/// helper class for iteration
class iteration_proxy_internal
{
public:
using difference_type = std::ptrdiff_t;
using value_type = iteration_proxy_internal;
using pointer = iteration_proxy_internal*;
using reference = iteration_proxy_internal&;
using iterator_category = std::input_iterator_tag;
private:
/// the iterator
IteratorType anchor;
@ -31,6 +39,9 @@ template<typename IteratorType> class iteration_proxy
public:
explicit iteration_proxy_internal(IteratorType it) noexcept : anchor(it) {}
iteration_proxy_internal(const iteration_proxy_internal&) = default;
iteration_proxy_internal& operator=(const iteration_proxy_internal&) = default;
/// dereference operator (needed for range-based for)
iteration_proxy_internal& operator*()
{
@ -46,6 +57,12 @@ template<typename IteratorType> class iteration_proxy
return *this;
}
/// equality operator (needed for InputIterator)
bool operator==(const iteration_proxy_internal& o) const noexcept
{
return anchor == o.anchor;
}
/// inequality operator (needed for range-based for)
bool operator!=(const iteration_proxy_internal& o) const noexcept
{