QSetIterator Class
template <typename T> class QSetIterator
The QSetIterator class provides a Java-style const iterator for QSet. More…
| Header | #include <QSetIterator> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Core) |
| Module | Nt Core C++ Classes |
List of all members, including inherited members
Public Functions
| QSetIterator(const QSet<T> &set) | |
| void | toFront() |
| bool | hasNext() const |
| const T & | next() |
| const T & | peekNext() const |
| bool | findNext(const T &v) |
Detailed Description
QSetIterator<T> iterates forward over a set without modifying it. The iterator points between values: next() returns the value it jumps over. A new iterator is positioned before the first value.
QSet<int> set = {1, 2, 3};
QSetIterator<int> it(set);
while (it.hasNext())
qDebug() << it.next();
See also QMutableSetIterator, QListIterator 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
QSetIterator::QSetIterator(const 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 QSetIterator::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 QSetIterator::hasNext() const
Returns true if there is at least one value ahead of the iterator; otherwise returns false.
See also next().
const T & QSetIterator::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() and peekNext().
const T & QSetIterator::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 QSetIterator::toFront()
Moves the iterator to the front of the set, before the first value.
See also next().