| 10876 | */ |
| 10877 | template<typename BasicJsonType> |
| 10878 | class iter_impl |
| 10879 | { |
| 10880 | /// allow basic_json to access private members |
| 10881 | friend iter_impl<typename std::conditional<std::is_const<BasicJsonType>::value, typename std::remove_const<BasicJsonType>::type, const BasicJsonType>::type>; |
| 10882 | friend BasicJsonType; |
| 10883 | friend iteration_proxy<iter_impl>; |
| 10884 | friend iteration_proxy_value<iter_impl>; |
| 10885 | |
| 10886 | using object_t = typename BasicJsonType::object_t; |
| 10887 | using array_t = typename BasicJsonType::array_t; |
| 10888 | // make sure BasicJsonType is basic_json or const basic_json |
| 10889 | static_assert(is_basic_json<typename std::remove_const<BasicJsonType>::type>::value, |
| 10890 | "iter_impl only accepts (const) basic_json"); |
| 10891 | |
| 10892 | public: |
| 10893 | |
| 10894 | /// The std::iterator class template (used as a base class to provide typedefs) is deprecated in C++17. |
| 10895 | /// The C++ Standard has never required user-defined iterators to derive from std::iterator. |
| 10896 | /// A user-defined iterator should provide publicly accessible typedefs named |
| 10897 | /// iterator_category, value_type, difference_type, pointer, and reference. |
| 10898 | /// Note that value_type is required to be non-const, even for constant iterators. |
| 10899 | using iterator_category = std::bidirectional_iterator_tag; |
| 10900 | |
| 10901 | /// the type of the values when the iterator is dereferenced |
| 10902 | using value_type = typename BasicJsonType::value_type; |
| 10903 | /// a type to represent differences between iterators |
| 10904 | using difference_type = typename BasicJsonType::difference_type; |
| 10905 | /// defines a pointer to the type iterated over (value_type) |
| 10906 | using pointer = typename std::conditional<std::is_const<BasicJsonType>::value, |
| 10907 | typename BasicJsonType::const_pointer, |
| 10908 | typename BasicJsonType::pointer>::type; |
| 10909 | /// defines a reference to the type iterated over (value_type) |
| 10910 | using reference = |
| 10911 | typename std::conditional<std::is_const<BasicJsonType>::value, |
| 10912 | typename BasicJsonType::const_reference, |
| 10913 | typename BasicJsonType::reference>::type; |
| 10914 | |
| 10915 | /// default constructor |
| 10916 | iter_impl() = default; |
| 10917 | |
| 10918 | /*! |
| 10919 | @brief constructor for a given JSON instance |
| 10920 | @param[in] object pointer to a JSON object for this iterator |
| 10921 | @pre object != nullptr |
| 10922 | @post The iterator is initialized; i.e. `m_object != nullptr`. |
| 10923 | */ |
| 10924 | explicit iter_impl(pointer object) noexcept : m_object(object) |
| 10925 | { |
| 10926 | JSON_ASSERT(m_object != nullptr); |
| 10927 | |
| 10928 | switch (m_object->m_type) |
| 10929 | { |
| 10930 | case value_t::object: |
| 10931 | { |
| 10932 | m_it.object_iterator = typename object_t::iterator(); |
| 10933 | break; |
| 10934 | } |
| 10935 | |