key_iterator Class

class QMultiMap::key_iterator

QMultiMap::key_iterator クラスは、QMultiMap キー用の STL スタイルの const イテレータを提供します。さらに...

パブリック関数

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 は基本的に と同じですが、 operator*() と operator->() は値の代わりにキーを返すという違いがあります。QMultiMap::const_iterator

ほとんどの用途では、QMultiMap::iteratorQMultiMap::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());

// 効率的、メモリ割り当て不要intnumPrimes=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も参照のこと

メンバ関数ドキュメント

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)

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

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

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

前置演算子-- (--i) は、直前の項目をカレントにし、新しいカレント項目を指すイテレータを返す。

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

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

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

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

postfix-- 演算子 (i--) は、直前の項目をカレントとし、直前の項目を指すイテレータを返します。

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

現在のアイテムのキーへのポインタを返します。

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

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

operator!=()も参照

© 2025 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.