From b702163c9a73c9bf88bd26fc0cd41c1bc327fa2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vicente=20Mataix=20Ferr=C3=A1ndiz?= Date: Tue, 23 Oct 2018 13:10:59 +0200 Subject: [PATCH] Adding to file imp_iterator --- .../nlohmann/detail/iterators/iter_impl.hpp | 48 +++++++++++++++++++ single_include/nlohmann/json.hpp | 1 - 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/include/nlohmann/detail/iterators/iter_impl.hpp b/include/nlohmann/detail/iterators/iter_impl.hpp index 6674c0645..2968eaff9 100644 --- a/include/nlohmann/detail/iterators/iter_impl.hpp +++ b/include/nlohmann/detail/iterators/iter_impl.hpp @@ -209,6 +209,54 @@ class iter_impl } public: + /// return whether the iterator can be dereferenced + constexpr bool is_begin() const noexcept + { + assert(m_object != nullptr); + + switch (m_object->m_type) + { + case value_t::object: + { + return m_it.object_iterator == m_object->m_value.object->begin(); + } + case value_t::array: + { + return m_it.array_iterator == m_object->m_value.array->begin(); + } + case value_t::null: + JSON_THROW(invalid_iterator::create(214, "cannot get value")); + default: + { + return m_it.primitive_iterator.is_begin(); + } + } + } + + /// return whether the iterator is at end + constexpr bool is_end() const noexcept + { + assert(m_object != nullptr); + + switch (m_object->m_type) + { + case value_t::object: + { + return m_it.object_iterator == m_object->m_value.object->end(); + } + case value_t::array: + { + return m_it.array_iterator == m_object->m_value.array->end(); + } + case value_t::null: + JSON_THROW(invalid_iterator::create(214, "cannot get value")); + default: + { + return m_it.primitive_iterator.is_end(); + } + } + } + /*! @brief return a reference to the value pointed to by the iterator @pre The iterator is initialized; i.e. `m_object != nullptr`. diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index a9a6dbcce..35a11da24 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -5647,7 +5647,6 @@ class iter_impl } public: - /// return whether the iterator can be dereferenced constexpr bool is_begin() const noexcept {