このページでは

QMultiMap::key_iterator Class

class QMultiMap::key_iterator

QMultiMap::key_iterator クラスは、QMultiMap のキーに対してSTLスタイルのconstイテレータを提供します。詳細...

パブリック関数

key_iterator()
QMultiMap<Key, T>::const_iterator base() const
bool operator!=(QMultiMap<Key, T>::key_iterator other) const
const Key &operator*() const
QMultiMap<Key, T>::key_iterator &operator++()
QMultiMap<Key, T>::key_iterator operator++(int)
QMultiMap<Key, T>::key_iterator &operator--()
QMultiMap<Key, T>::key_iterator operator--(int)
const Key *operator->() const
bool operator==(QMultiMap<Key, T>::key_iterator other) const

詳細な説明

QMultiMap::key_iterator は基本的にQMultiMap::const_iterator と同じですが、operator*()およびoperator->()が値ではなくキーを返す点が異なります。

ほとんどの場合、QMultiMap::iterator およびQMultiMap::const_iterator を使用すべきであり、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;
}

しかし、QMultiMap のキーとSTLスタイルのアルゴリズムとの相互運用性を実現するには、値ではなくキーを参照するイテレータが必要です。QMultiMap::key_iterator を使用すれば、QMultiMap::keys()を呼び出すことなく、キーの範囲に対してアルゴリズムを適用できます。 ()の呼び出しは、QMultiMap の反復処理1回と、一時的なQList を作成するためのメモリ割り当てを要するため、非効率的です。

// 非効率的。keys() の実行コストが高い
QList<int>keys=multimap.keys();
intnumPrimes=std::count_if(multimap.cbegin(),multimap.cend(),isPrimeNumber);
qDeleteAll(multimap2.keys());

// 効率的、メモリ割り当ては不要
intprimeNums=std::count_if(multimap.keyBegin(),multimap.keyEnd(),isPrimeNumber);
qDeleteAll(multimap2.keyBegin(), multimap2.keyEnd());

QMultiMap::key_iterator const であるため、キーを変更することはできません。

QMultiMap::key_iterator のデフォルトコンストラクタは、初期化されていないイテレータを作成します。QMultiMap::keyBegin()やQMultiMap::keyEnd()のようなQMultiMap 関数を使用して、イテレータを初期化する必要があります。

警告: 暗黙的に共有されるコンテナ上のイテレータは 、STLイテレータとまったく同じように動作しません。そのコンテナ上でイテレータがアクティブな間は、コンテナのコピーを避けるべきです。詳細については、「暗黙的な共有によるイテレータの問題」を参照してください。

「 QMultiMap::const_iterator 」および「QMultiMap::iterator 」も参照してください 。

メンバ関数のドキュメント

[default] key_iterator::key_iterator()

key_iterator のインスタンスをデフォルトコンストラクタで生成します。

QMultiMap<Key, T>::const_iterator key_iterator::base() const

この `key_iterator ` の基となる `const_iterator ` を返します。

bool key_iterator::operator!=(QMultiMap<Key, T>::key_iterator other) const

other がこのイテレータとは異なる項目を指している場合はtrue を返し、そうでない場合はfalse を返します。

operator==()も参照してください 。

const Key &key_iterator::operator*() const

現在の項目のキーを返します。

QMultiMap<Key, T>::key_iterator &key_iterator::operator++()

接頭辞++ 演算子(++i )は、イテレータをハッシュ内の次の項目へと進め、新しい現在の項目へのイテレータを返します。

QMultiMap::keyEnd() に対してこの関数を呼び出すと、未定義の結果となります。

operator--()も参照してください 。

QMultiMap<Key, T>::key_iterator key_iterator::operator++(int)

後置演算子「++ 」(i++ )は、イテレータをハッシュ内の次の項目に進め、前の項目へのイテレータを返します。

これはオーバーロードされた関数です。

QMultiMap<Key, T>::key_iterator &key_iterator::operator--()

プレフィックス演算子 `-- ` (--i) は、その直前の要素を現在の要素として設定し、新しい現在の要素を指すイテレータを返します。

QMultiMap::keyBegin() に対してこの関数を呼び出すと、未定義の結果となります。

operator++()も参照してください 。

QMultiMap<Key, T>::key_iterator key_iterator::operator--(int)

後置演算子 `-- ` (i--) は、直前の要素を現在の要素とし、その前の要素を指すイテレータを返します。

これはオーバーロードされた関数です。

const Key *key_iterator::operator->() const

現在の項目のキーへのポインタを返します。

bool key_iterator::operator==(QMultiMap<Key, T>::key_iterator other) const

other がこのイテレータと同じ項目を指している場合はtrue を返し、そうでない場合はfalse を返します。

operator!=()も参照してください 。

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.