The QMultiMap::key_iterator 类提供 STL 样式 const 迭代器为 QMultiMap keys. 更多...
const_iterator | base () const |
bool | operator!= (key_iterator other ) const |
const Key & | operator* () const |
key_iterator & | operator++ () |
key_iterator | operator++ (int) |
key_iterator & | operator-- () |
key_iterator | operator-- (int) |
const Key * | operator-> () const |
bool | operator== (key_iterator other ) const |
QMultiMap::key_iterator is essentially the same as QMultiMap::const_iterator with the difference that operator*() and operator->() return a key instead of a value.
For most uses QMultiMap::iterator and QMultiMap::const_iterator should be used, you can easily access the key by calling QMultiMap::iterator::key ():
for (auto it = multimap.cbegin(), end = multimap.cend(); it != end; ++it) { cout << "The key: " << it.key() << endl cout << "The value: " << qPrintable(it.value()) << endl; cout << "Also the value: " << qPrintable(*it) << endl; }
However, to have interoperability between QMultiMap 's keys and STL-style algorithms we need an iterator that dereferences to a key instead of a value. With QMultiMap::key_iterator we can apply an algorithm to a range of keys without having to call QMultiMap::keys (), which is inefficient as it costs one QMultiMap iteration and memory allocation to create a temporary QList .
// Inefficient, keys() is expensive QList<int> keys = multimap.keys(); int numPrimes = std::count_if(multimap.cbegin(), multimap.cend(), isPrimeNumber); qDeleteAll(multimap2.keys()); // Efficient, no memory allocation needed int numPrimes = std::count_if(multimap.keyBegin(), multimap.keyEnd(), isPrimeNumber); qDeleteAll(multimap2.keyBegin(), multimap2.keyEnd());
QMultiMap::key_iterator is const, it's not possible to modify the key.
默认 QMultiMap::key_iterator constructor creates an uninitialized iterator. You must initialize it using a QMultiMap function like QMultiMap::keyBegin () 或 QMultiMap::keyEnd ().
警告: Iterators on implicitly shared containers do not work exactly like STL-iterators. You should avoid copying a container while iterators are active on that container. For more information, read 隐式共享迭代器问题 .
另请参阅 QMultiMap::const_iterator and QMultiMap::iterator .
Returns the underlying const_iterator this key_iterator is based on.
返回
true
if
other
指向与此迭代器不同的项;否则返回
false
.
另请参阅 operator== ().
Returns the current item's key.
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 function on QMultiMap::keyEnd () leads to undefined results.
另请参阅 operator-- ().
这是重载函数。
The postfix
++
operator (
i++
) advances the iterator to the next item in the hash and returns an iterator to the previous item.
The prefix
--
operator (
--i
) makes the preceding item current and returns an iterator pointing to the new current item.
Calling this function on QMultiMap::keyBegin () leads to undefined results.
另请参阅 operator++ ().
这是重载函数。
The postfix
--
operator (
i--
) makes the preceding item current and returns an iterator pointing to the previous item.
Returns a pointer to the current item's key.
返回
true
if
other
points to the same item as this iterator; otherwise returns
false
.
另请参阅 operator!= ().