Template Class iter_impl

Class Documentation

template<typename BasicJsonType>
class iter_impl

a template for a bidirectional iterator for the basic_json class This class implements a both iterators (iterator and const_iterator) for the basic_json class.

Since

version 1.0.0, simplified in version 2.0.9, change to bidirectional iterators in version 3.0.0 (see https://github.com/nlohmann/json/issues/593)

Note

An iterator is called initialized when a pointer to a JSON value has been set (e.g., by a constructor or a copy assignment). If the iterator is default-constructed, it is uninitialized and most methods are undefined. The library uses assertions to detect calls on uninitialized iterators.** @requirement The class satisfies the following concept requirements:

  • BidirectionalIterator: The iterator that can be moved can be moved in both directions (i.e. incremented and decremented).

Public Types

using iterator_category = std::bidirectional_iterator_tag

The std::iterator class template (used as a base class to provide typedefs) is deprecated in C++17. The C++ Standard has never required user-defined iterators to derive from std::iterator. A user-defined iterator should provide publicly accessible typedefs named iterator_category, value_type, difference_type, pointer, and reference. Note that value_type is required to be non-const, even for constant iterators.

using value_type = typename BasicJsonType::value_type

the type of the values when the iterator is dereferenced

using difference_type = typename BasicJsonType::difference_type

a type to represent differences between iterators

using pointer = typename std::conditional<std::is_const<BasicJsonType>::value, typename BasicJsonType::const_pointer, typename BasicJsonType::pointer>::type

defines a pointer to the type iterated over (value_type)

using reference = typename std::conditional<std::is_const<BasicJsonType>::value, typename BasicJsonType::const_reference, typename BasicJsonType::reference>::type

defines a reference to the type iterated over (value_type)

using iterator_category = std::bidirectional_iterator_tag

The std::iterator class template (used as a base class to provide typedefs) is deprecated in C++17. The C++ Standard has never required user-defined iterators to derive from std::iterator. A user-defined iterator should provide publicly accessible typedefs named iterator_category, value_type, difference_type, pointer, and reference. Note that value_type is required to be non-const, even for constant iterators.

using value_type = typename BasicJsonType::value_type

the type of the values when the iterator is dereferenced

using difference_type = typename BasicJsonType::difference_type

a type to represent differences between iterators

using pointer = typename std::conditional<std::is_const<BasicJsonType>::value, typename BasicJsonType::const_pointer, typename BasicJsonType::pointer>::type

defines a pointer to the type iterated over (value_type)

using reference = typename std::conditional<std::is_const<BasicJsonType>::value, typename BasicJsonType::const_reference, typename BasicJsonType::reference>::type

defines a reference to the type iterated over (value_type)

Public Functions

iter_impl() = default

default constructor

allow basic_json to access private members

inline explicit iter_impl(pointer object) noexcept

constructor for a given JSON instance

Parameters:

object[in] pointer to a JSON object for this iterator

Pre:

object != nullptr

Post:

The iterator is initialized; i.e. m_object != nullptr.

inline iter_impl(const iter_impl<const BasicJsonType> &other) noexcept

const copy constructor

Note

The conventional copy constructor and copy assignment are implicitly defined. Combined with the following converting constructor and assignment, they support: (1) copy from iterator to iterator, (2) copy from const iterator to const iterator, and (3) conversion from iterator to const iterator. However conversion from const iterator to iterator is not defined.

Note

This copy constructor had to be defined explicitly to circumvent a bug occurring on msvc v19.0 compiler (VS 2015) debug build. For more information refer to: https://github.com/nlohmann/json/issues/1608

Parameters:

other[in] const iterator to copy from

inline iter_impl &operator=(const iter_impl<const BasicJsonType> &other) noexcept

converting assignment

Note

It is not checked whether other is initialized.

Parameters:

other[in] const iterator to copy from

Returns:

const/non-const iterator

inline iter_impl(const iter_impl<typename std::remove_const<BasicJsonType>::type> &other) noexcept

converting constructor

Note

It is not checked whether other is initialized.

Parameters:

other[in] non-const iterator to copy from

inline iter_impl &operator=(const iter_impl<typename std::remove_const<BasicJsonType>::type> &other) noexcept

converting assignment

Note

It is not checked whether other is initialized.

Parameters:

other[in] non-const iterator to copy from

Returns:

const/non-const iterator

inline reference operator*() const

return a reference to the value pointed to by the iterator

Pre:

The iterator is initialized; i.e. m_object != nullptr.

inline pointer operator->() const

dereference the iterator

Pre:

The iterator is initialized; i.e. m_object != nullptr.

inline iter_impl const operator++(int)

post-increment (it++)

Pre:

The iterator is initialized; i.e. m_object != nullptr.

inline iter_impl &operator++()

pre-increment (++it)

Pre:

The iterator is initialized; i.e. m_object != nullptr.

inline iter_impl const operator--(int)

post-decrement (it&#8212;)

Pre:

The iterator is initialized; i.e. m_object != nullptr.

inline iter_impl &operator--()

pre-decrement (&#8212;it)

Pre:

The iterator is initialized; i.e. m_object != nullptr.

inline bool operator==(const iter_impl &other) const

comparison: equal

Pre:

The iterator is initialized; i.e. m_object != nullptr.

inline bool operator!=(const iter_impl &other) const

comparison: not equal

Pre:

The iterator is initialized; i.e. m_object != nullptr.

inline bool operator<(const iter_impl &other) const

comparison: smaller

Pre:

The iterator is initialized; i.e. m_object != nullptr.

inline bool operator<=(const iter_impl &other) const

comparison: less than or equal

Pre:

The iterator is initialized; i.e. m_object != nullptr.

inline bool operator>(const iter_impl &other) const

comparison: greater than

Pre:

The iterator is initialized; i.e. m_object != nullptr.

inline bool operator>=(const iter_impl &other) const

comparison: greater than or equal

Pre:

The iterator is initialized; i.e. m_object != nullptr.

inline iter_impl &operator+=(difference_type i)

add to iterator

Pre:

The iterator is initialized; i.e. m_object != nullptr.

inline iter_impl &operator-=(difference_type i)

subtract from iterator

Pre:

The iterator is initialized; i.e. m_object != nullptr.

inline iter_impl operator+(difference_type i) const

add to iterator

Pre:

The iterator is initialized; i.e. m_object != nullptr.

inline iter_impl operator-(difference_type i) const

subtract from iterator

Pre:

The iterator is initialized; i.e. m_object != nullptr.

inline difference_type operator-(const iter_impl &other) const

return difference

Pre:

The iterator is initialized; i.e. m_object != nullptr.

inline reference operator[](difference_type n) const

access to successor

Pre:

The iterator is initialized; i.e. m_object != nullptr.

inline const object_t::key_type &key() const

return the key of an object iterator

Pre:

The iterator is initialized; i.e. m_object != nullptr.

inline reference value() const

return the value of an iterator

Pre:

The iterator is initialized; i.e. m_object != nullptr.

iter_impl() = default

default constructor

inline explicit iter_impl(pointer object) noexcept

constructor for a given JSON instance

Parameters:

object[in] pointer to a JSON object for this iterator

Pre:

object != nullptr

Post:

The iterator is initialized; i.e. m_object != nullptr.

inline iter_impl(const iter_impl<const BasicJsonType> &other) noexcept

const copy constructor

Note

The conventional copy constructor and copy assignment are implicitly defined. Combined with the following converting constructor and assignment, they support: (1) copy from iterator to iterator, (2) copy from const iterator to const iterator, and (3) conversion from iterator to const iterator. However conversion from const iterator to iterator is not defined.

Note

This copy constructor had to be defined explicitly to circumvent a bug occurring on msvc v19.0 compiler (VS 2015) debug build. For more information refer to: https://github.com/nlohmann/json/issues/1608

Parameters:

other[in] const iterator to copy from

inline iter_impl &operator=(const iter_impl<const BasicJsonType> &other) noexcept

converting assignment

Note

It is not checked whether other is initialized.

Parameters:

other[in] const iterator to copy from

Returns:

const/non-const iterator

inline iter_impl(const iter_impl<typename std::remove_const<BasicJsonType>::type> &other) noexcept

converting constructor

Note

It is not checked whether other is initialized.

Parameters:

other[in] non-const iterator to copy from

inline iter_impl &operator=(const iter_impl<typename std::remove_const<BasicJsonType>::type> &other) noexcept

converting assignment

Note

It is not checked whether other is initialized.

Parameters:

other[in] non-const iterator to copy from

Returns:

const/non-const iterator

inline reference operator*() const

return a reference to the value pointed to by the iterator

Pre:

The iterator is initialized; i.e. m_object != nullptr.

inline pointer operator->() const

dereference the iterator

Pre:

The iterator is initialized; i.e. m_object != nullptr.

inline iter_impl const operator++(int)

post-increment (it++)

Pre:

The iterator is initialized; i.e. m_object != nullptr.

inline iter_impl &operator++()

pre-increment (++it)

Pre:

The iterator is initialized; i.e. m_object != nullptr.

inline iter_impl const operator--(int)

post-decrement (it&#8212;)

Pre:

The iterator is initialized; i.e. m_object != nullptr.

inline iter_impl &operator--()

pre-decrement (&#8212;it)

Pre:

The iterator is initialized; i.e. m_object != nullptr.

inline bool operator==(const iter_impl &other) const

comparison: equal

Pre:

The iterator is initialized; i.e. m_object != nullptr.

inline bool operator!=(const iter_impl &other) const

comparison: not equal

Pre:

The iterator is initialized; i.e. m_object != nullptr.

inline bool operator<(const iter_impl &other) const

comparison: smaller

Pre:

The iterator is initialized; i.e. m_object != nullptr.

inline bool operator<=(const iter_impl &other) const

comparison: less than or equal

Pre:

The iterator is initialized; i.e. m_object != nullptr.

inline bool operator>(const iter_impl &other) const

comparison: greater than

Pre:

The iterator is initialized; i.e. m_object != nullptr.

inline bool operator>=(const iter_impl &other) const

comparison: greater than or equal

Pre:

The iterator is initialized; i.e. m_object != nullptr.

inline iter_impl &operator+=(difference_type i)

add to iterator

Pre:

The iterator is initialized; i.e. m_object != nullptr.

inline iter_impl &operator-=(difference_type i)

subtract from iterator

Pre:

The iterator is initialized; i.e. m_object != nullptr.

inline iter_impl operator+(difference_type i) const

add to iterator

Pre:

The iterator is initialized; i.e. m_object != nullptr.

inline iter_impl operator-(difference_type i) const

subtract from iterator

Pre:

The iterator is initialized; i.e. m_object != nullptr.

inline difference_type operator-(const iter_impl &other) const

return difference

Pre:

The iterator is initialized; i.e. m_object != nullptr.

inline reference operator[](difference_type n) const

access to successor

Pre:

The iterator is initialized; i.e. m_object != nullptr.

inline const object_t::key_type &key() const

return the key of an object iterator

Pre:

The iterator is initialized; i.e. m_object != nullptr.

inline reference value() const

return the value of an iterator

Pre:

The iterator is initialized; i.e. m_object != nullptr.

Friends

inline friend iter_impl operator+(difference_type i, const iter_impl &it)

addition of distance and iterator

Pre:

The iterator is initialized; i.e. m_object != nullptr.

inline friend iter_impl operator+(difference_type i, const iter_impl &it)

addition of distance and iterator

Pre:

The iterator is initialized; i.e. m_object != nullptr.