MongoDB C++ Driver 4.2.0
Loading...
Searching...
No Matches
mongocxx::v1::cursor::iterator Class Reference

#include <mongocxx/v1/cursor.hpp>

Description

An iterator over the results of an associated cursor.

Attention
This feature is experimental! It is not ready for use!
Important
All iterators associated with the same cursor object share the same state.
The end iterator has no associated cursor.
Note
This iterator almost satisfies Cpp17ForwardIterator, but std::iterator_traits<T>::reference is defined as value_type, similar to std::vector<bool>::iterator and std::istreambuf_iterator<T>. Therefore, this iterator only fully satisfies Cpp17InputIterator.
See also

Public Types

using difference_type = std::ptrdiff_t
 Provide std::iterator_traits<T>::difference_type.
using iterator_category = std::input_iterator_tag
 Provide std::iterator_traits<T>::iterator_category.
using pointer = value_type const*
 Provide std::iterator_traits<T>::pointer.
using reference = value_type
 Provide std::iterator_traits<T>::reference.
using value_type = bsoncxx::v1::document::view
 Provide std::iterator_traits<T>::value_type.

Public Member Functions

 iterator ()
 Initialize as an end iterator.
 iterator (iterator &&other) noexcept
 Move construction.
 iterator (iterator const &other)
 Copy construction.
 ~iterator ()
 Destroy this object.
value_type operator* () const
 Access the current cursor result document.
iteratoroperator++ ()
 Increment this iterator.
iteratoroperator++ (int)
 Increment this iterator.
pointer operator-> () const
 Access the current result document.
iteratoroperator= (iterator &&other) noexcept
 Move assignment.
iteratoroperator= (iterator const &other)
 Copy assignment.

Friends

bool operator!= (iterator const &lhs, iterator const &rhs)
 Equivalent to !(lhs == rhs).
bool operator== (iterator const &lhs, iterator const &rhs)
 Equality comparison.

Member Typedef Documentation

◆ difference_type

Provide std::iterator_traits<T>::difference_type.

◆ iterator_category

using mongocxx::v1::cursor::iterator::iterator_category = std::input_iterator_tag

Provide std::iterator_traits<T>::iterator_category.

◆ pointer

Provide std::iterator_traits<T>::pointer.

◆ reference

Provide std::iterator_traits<T>::reference.

◆ value_type

Constructor & Destructor Documentation

◆ ~iterator()

mongocxx::v1::cursor::iterator::~iterator ( )

Destroy this object.

Warning
Invalidates all associated views.

◆ iterator() [1/3]

mongocxx::v1::cursor::iterator::iterator ( iterator && other)
noexcept

Move construction.

Postconditions:
  • other is in an assign-or-destroy-only state.

◆ iterator() [2/3]

mongocxx::v1::cursor::iterator::iterator ( iterator const & other)

Copy construction.

◆ iterator() [3/3]

mongocxx::v1::cursor::iterator::iterator ( )

Initialize as an end iterator.

Member Function Documentation

◆ operator*()

value_type mongocxx::v1::cursor::iterator::operator* ( ) const

Access the current cursor result document.

◆ operator++() [1/2]

iterator & mongocxx::v1::cursor::iterator::operator++ ( )

Increment this iterator.

Advance the underlying cursor to obtain the next result document. Compare equal to the end iterator when there are no result documents available.

Note
Pre-increment and post-increment are equivalent.
Warning
Invalidates all views to the current result document.
Exceptions
mongocxx::v1::server_errorwhen a server-side error is encountered and a raw server error is available.
mongocxx::v1::exceptionfor all other runtime errors.

◆ operator++() [2/2]

iterator & mongocxx::v1::cursor::iterator::operator++ ( int )
inline

Increment this iterator.

Advance the underlying cursor to obtain the next result document. Compare equal to the end iterator when there are no result documents available.

Note
Pre-increment and post-increment are equivalent.
Warning
Invalidates all views to the current result document.
Exceptions
mongocxx::v1::server_errorwhen a server-side error is encountered and a raw server error is available.
mongocxx::v1::exceptionfor all other runtime errors.

◆ operator->()

pointer mongocxx::v1::cursor::iterator::operator-> ( ) const

Access the current result document.

Preconditions:
  • *this does not compare equal to the end iterator.
Returns
Empty when there is no result document available.

◆ operator=() [1/2]

iterator & mongocxx::v1::cursor::iterator::operator= ( iterator && other)
noexcept

Move assignment.

Postconditions:
  • other is in an assign-or-destroy-only state.

◆ operator=() [2/2]

iterator & mongocxx::v1::cursor::iterator::operator= ( iterator const & other)

Copy assignment.

◆ operator!=

bool operator!= ( iterator const & lhs,
iterator const & rhs )
friend

Equivalent to !(lhs == rhs).

◆ operator==

bool operator== ( iterator const & lhs,
iterator const & rhs )
friend

Equality comparison.

lhs and rhs compare equal when:

  • both are associated with the same cursor object, or
  • both are end iterators, or
  • one is an end iterator and the other has no result document available.

The documentation for this class was generated from the following file: