CopperSpice API
1.9.1
|
STL style non-const iterator for QMultiHash. More...
Public Typedefs | |
using | iterator_category = std::forward_iterator_tag |
using | pointer = Val * |
using | reference = Val & |
using | size_type = typename std::unordered_multimap< Key, Val, Hash, KeyEqual >::difference_type |
Public Methods | |
iterator () = default | |
const Key & | key () const |
bool | operator!= (iterator other) const |
Val & | operator* () const |
iterator | operator+ (size_type n) const |
iterator & | operator++ () |
iterator | operator++ (int) |
iterator & | operator+= (size_type n) |
iterator | operator- (size_type n) const |
iterator & | operator-= (size_type n) |
Val * | operator-> () const |
bool | operator== (iterator other) const |
std::pair< const Key, Val > & | pair () const |
Val & | value () const |
Friends | |
class | QMultiHash< Key, Val, Hash, KeyEqual > |
The QMultiHash::iterator class provides an STL style non-const iterator for QMultiHash. QMultiHash features both STL style iterators and Java style iterators.
After construction you must initialize the iterator using a method like QMultiHash::constBegin(), QMultiHash::constEnd(), or QMultiHash::find() before you can start iterating. The following is an example which prints all of the (key, value) pairs in the container.
Unlike QMap which orders its items by key, QHash stores its items in an arbitrary order. The only guarantee is items which share the same key will appear consecutively.
The following is an example which increments every value stored in the QHash by 2:
Here is an example which removes all of the items whose key is a string starting with an underscore character.
The call to QMultiHash::erase() removes the item pointed to by the iterator from the hash and returns an iterator to the next item. Here is another way of removing an item while iterating:
It might be tempting to write code like the following. This code will potentially crash in ++iter
, because iter
is invalid after the call to erase().
QMultiHash< Key, Val, Hash, KeyEqual >::iterator::iterator_category |
Equivalent to std::bidirectional_iterator_tag indicating this iterator is a bidirectional iterator.
QMultiHash< Key, Val, Hash, KeyEqual >::iterator::pointer |
Equivalent to value_type *.
QMultiHash< Key, Val, Hash, KeyEqual >::iterator::reference |
Equivalent to value_type &.
QMultiHash< Key, Val, Hash, KeyEqual >::iterator::size_type |
Equivalent to the native size type of this container.
|
default |
Constructs an uninitialized iterator.
Methods like key(), value(), and operator++() must not be called on an uninitialized iterator. Use operator=() to assign a value to it before using it.
|
inline |
Returns the current item's key as a const reference.
There is no direct way of changing an item's key through an iterator, although it can be done by calling QMultiHash::erase() followed by QMultiHash::insert() or QMultiHash::insertMulti().
|
inline |
Returns true if other points to a different item than this iterator, otherwise it returns false.
|
inline |
|
inline |
Returns an iterator to the item at n positions forward from this iterator. If n is negative the iterator goes backward.
This operation can be slow for large values of n.
|
inline |
The prefix ++ operator (++i
) advances the iterator to the next item in the hash and returns an iterator to the new current item.
Calling this method on QMultiHash::end() leads to undefined behavior.
|
inline |
The postfix ++ operator (i++
) advances the iterator to the next item in the hash and returns an iterator to the previously current item.
|
inline |
Advances the iterator by n items. If n is negative the iterator goes backward.
|
inline |
Returns an iterator to the item at n positions backward from this iterator. If n is negative the iterator goes forward.
This operation can be slow or large values of n.
|
inline |
Makes the iterator go back by n items. If n is negative the iterator goes forward.
|
inline |
Returns a pointer to the current item's value.
|
inline |
Returns true if other points to the same item as this iterator, otherwise it returns false.
|
inline |
Returns the current item's key and value as a pair.
|
inline |
Returns a reference to the value for the current item. You can change the value of an item by using value() on the left side of an assignment.