6.0.0-rc4Source

QMutableSetIterator Class

template <typename T> class QMutableSetIterator

The QMutableSetIterator class provides a Java-style non-const iterator for QSet. More…

Header#include <QMutableSetIterator>
CMaketarget_link_libraries(app PRIVATE Nt::Core)
ModuleNt Core C++ Classes

List of all members, including inherited members

Public Functions

QMutableSetIterator(QSet<T> &set)
voidtoFront()
boolhasNext() const
const T &next()
const T &peekNext() const
boolfindNext(const T &v)
voidremove()
const T &value() const

Detailed Description

QMutableSetIterator<T> iterates forward over a set and can remove values from it. The iterator points between values: next() returns the value it jumps over, and remove() removes that value.

QSet<int> set = {1, 2, 3, 4};
QMutableSetIterator<int> it(set);
while (it.hasNext())
    if (it.next() % 2 == 0)
        it.remove();

Values in a set cannot be changed in place, so unlike the list and map iterators there is no setValue().

See also QSetIterator, QMutableListIterator and QSet.

Differences from Qt

The iterator moves forward only: there is no toBack(), hasPrevious(), previous(), peekPrevious() or findPrevious(), and it cannot be assigned a new set.

Member Function Documentation

[explicit] QMutableSetIterator::QMutableSetIterator(QSet<T> &set)

Constructs an iterator for traversing set. The iterator is set to be at the front of the set, before the first value.

See also toFront().

bool QMutableSetIterator::findNext(const T &v)

Searches for v forward from the iterator position. Returns true if a value equal to v is found, leaving the iterator just after it; otherwise returns false and leaves the iterator at the back of the set.

bool QMutableSetIterator::hasNext() const

Returns true if there is at least one value ahead of the iterator; otherwise returns false.

See also next().

const T & QMutableSetIterator::next()

Returns the next value and advances the iterator by one position. Calling this function when the iterator is at the back of the set is undefined.

See also hasNext(), peekNext() and remove().

const T & QMutableSetIterator::peekNext() const

Returns the next value without moving the iterator. Calling this function when the iterator is at the back of the set is undefined.

See also hasNext() and next().

void QMutableSetIterator::remove()

Removes the value that next() last returned. Does nothing if next() has not been called since the iterator was created, moved to the front or last removed a value.

See also next().

void QMutableSetIterator::toFront()

Moves the iterator to the front of the set, before the first value.

See also next().

const T & QMutableSetIterator::value() const

Returns the value that next() last returned. Calling this function before next() is undefined.

See also next() and remove().