QAssocConstIterator Class
template <typename C, typename K, typename V, bool Bidirectional> class QAssocConstIterator
The QAssocConstIterator class provides the Java-style const iterator behind QMapIterator, QMultiMapIterator and QHashIterator. More…
| Header | #include <QtCore/qiterator.h> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Core) |
| Module | Nt Core C++ Classes |
List of all members, including inherited members
Public Types
| typedef | Item |
Public Functions
| QAssocConstIterator(const C &container) | |
| QAssocConstIterator & | operator=(const C &container) |
| void | toFront() |
| void | toBack() |
| bool | hasNext() const |
| It | next() |
| It | peekNext() const |
| const K & | key() const |
| const V & | value() const |
| bool | findNext(const V &v) |
| bool | hasPrevious() const |
| It | previous() |
| It | peekPrevious() const |
| bool | findPrevious(const V &v) |
Detailed Description
QAssocConstIterator<C, K, V, Bidirectional> iterates over an associative container C with key type K and value type V without modifying it. It points between items: next() returns the item it jumps over, and key() and value() refer to that item. Use the aliases QMapIterator, QMultiMapIterator and QHashIterator rather than naming this class.
QMap<QString, int> map = {{"a", 1}, {"b", 2}};
QMapIterator<QString, int> it(map);
while (it.hasNext()) {
it.next();
qDebug() << it.key() << it.value();
}
When Bidirectional is false, as for QHashIterator, the functions that move backward (hasPrevious(), previous(), peekPrevious() and findPrevious()) are not available.
See also QAssocMutableIterator and QListIterator.
Differences from Qt
next(), peekNext(), previous() and peekPrevious() return a const iterator of the container rather than a key-value item, and the iterator type is exposed as Item.
Member Type Documentation
typedef QAssocConstIterator::Item
The type returned by next(), peekNext(), previous() and peekPrevious(): a const iterator of the container that provides key() and value().
Member Function Documentation
QAssocConstIterator::QAssocConstIterator(const C &container)
Constructs an iterator for traversing container. The iterator is set to be at the front of the container, before the first item.
See also toFront().
bool QAssocConstIterator::findNext(const V &v)
Searches for the value v forward from the iterator position. Returns true if an item with that value is found, leaving the iterator just after it so that key() and value() describe it; otherwise returns false and leaves the iterator at the back.
See also findPrevious().
template <bool B = Bidirectional, typename = std::enable_if_t<B>>bool QAssocConstIterator::findPrevious(const V &v)
Searches for the value v backward from the iterator position. Returns true if an item with that value is found, leaving the iterator just before it so that key() and value() describe it; otherwise returns false and leaves the iterator at the front. Only available when the container is bidirectional.
See also findNext().
bool QAssocConstIterator::hasNext() const
Returns true if there is at least one item ahead of the iterator; otherwise returns false.
See also hasPrevious() and next().
template <bool B = Bidirectional, typename = std::enable_if_t<B>>bool QAssocConstIterator::hasPrevious() const
Returns true if there is at least one item behind the iterator; otherwise returns false. Only available when the container is bidirectional.
See also hasNext() and previous().
const K & QAssocConstIterator::key() const
Returns the key of the item that was last jumped over by next() or previous().
See also value().
It QAssocConstIterator::next()
Returns the next item and advances the iterator by one position. The key and value of the returned item are then available from key() and value(). Calling this function when the iterator is at the back is undefined.
See also hasNext(), peekNext() and previous().
QAssocConstIterator & QAssocConstIterator::operator=(const C &container)
Makes the iterator operate on container and moves it to the front. Returns a reference to this iterator.
It QAssocConstIterator::peekNext() const
Returns the next item without moving the iterator. Calling this function when the iterator is at the back is undefined.
See also hasNext(), next() and peekPrevious().
template <bool B = Bidirectional, typename = std::enable_if_t<B>>It QAssocConstIterator::peekPrevious() const
Returns the previous item without moving the iterator. Only available when the container is bidirectional. Calling this function when the iterator is at the front is undefined.
See also hasPrevious(), previous() and peekNext().
template <bool B = Bidirectional, typename = std::enable_if_t<B>>It QAssocConstIterator::previous()
Returns the previous item and moves the iterator back by one position. Only available when the container is bidirectional. Calling this function when the iterator is at the front is undefined.
See also hasPrevious(), peekPrevious() and next().
void QAssocConstIterator::toBack()
Moves the iterator to the back of the container, after the last item.
See also toFront() and previous().
void QAssocConstIterator::toFront()
Moves the iterator to the front of the container, before the first item.
const V & QAssocConstIterator::value() const
Returns the value of the item that was last jumped over by next() or previous().
See also key().