From 5ac2d650475973b7d0d85f9f8b3e9791005d1845 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vicente=20Mataix=20Ferr=C3=A1ndiz?= Date: Tue, 23 Oct 2018 13:06:01 +0200 Subject: [PATCH] Adding to single include --- single_include/nlohmann/json.hpp | 49 ++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 1de78dfc7..a9a6dbcce 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -5647,6 +5647,55 @@ 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`.