const_iterator Class

class QMultiMap::const_iterator

QMultiMap::const_iterator クラスは、QMultiMap 用の STL スタイルの const イテレータを提供します。詳細...

パブリック型

パブリック関数

const_iterator()
const_iterator(const QMultiMap<Key, T>::iterator &other)
const Key &key() const
const T &value() const
const T &operator*() const
QMultiMap<Key, T>::const_iterator &operator++()
QMultiMap<Key, T>::const_iterator operator++(int)
QMultiMap<Key, T>::const_iterator &operator--()
QMultiMap<Key, T>::const_iterator operator--(int)
const T *operator->() const
bool operator!=(const QMultiMap<Key, T>::const_iterator &lhs, const QMultiMap<Key, T>::const_iterator &rhs)
bool operator==(const QMultiMap<Key, T>::const_iterator &lhs, const QMultiMap<Key, T>::const_iterator &rhs)

詳しい説明

QMultiMap<Key, T>::const_iterator を使うと、QMultiMap を繰り返し処理できます。QMultiMap を繰り返し処理しながら変更したい場合は、代わりにQMultiMap::iterator を使う必要があります。イテレータを通してQMultiMap を変更する必要がない限り、constQMultiMap 以外でもQMultiMap::const_iterator を使用するのが一般的です。constイテレータの方が若干高速で、コードの可読性も向上します。

デフォルトのQMultiMap::const_iterator コンストラクタは、初期化されていないイテレータを作成します。QMultiMap::cbegin ()、QMultiMap::cend ()、QMultiMap::constFind ()のようなQMultiMap 関数を使用して初期化しなければなりません。以下は、マップに格納されたすべての(キー、値)ペアを表示する典型的なループです:

QMultiMap<QString, int> multi;
multimap.insert("January", 1);
multimap.insert("February", 2);
...
multimap.insert("December", 12);

for (auto i = multimap.cbegin(), end = multimap.cend(); i != end; ++i)
    cout << qPrintable(i.key()) << ": " << i.value() << endl;

以下は、値が10より大きい項目をすべて削除する例である:

QMultiMap<QString, int>::const_iterator i = multimap.cbegin();
while (i != multimap.cend()) {
    if (i.value() > 10)
        i = multimap.erase(i);
    else
        ++i;
}

QMultiHash 、アイテムを任意の順序で格納するのとは異なり、QMultiMap 、アイテムをキー順に格納する。同じキーを共有する項目は、最近挿入された値から最近挿入されなかった値まで、連続して表示されます。

複数のイテレータを同じマルチ・マップで使用することができる。マップに項目を追加しても、既存のイテレータは有効です。マップから項目を削除すると、削除された項目を指すイテレータはぶら下がったイテレータになります。

警告 暗黙的に共有されたコンテナ上のイテレータは、STLイテレータのようには動作しません。イテレータがコンテナ上でアクティブになっている間は、コンテナをコピーしないようにする必要があります。詳細については、暗黙的共有イテレータ問題を参照してください。

QMultiMap::iteratorQMultiMap::key_iteratorQMultiMap::const_key_value_iteratorも参照のこと

メンバ型ドキュメント

[alias] const_iterator::iterator_category

このイテレータが双方向イテレータであることを示すstd::bidirectional_iterator_tagのシノニム。

メンバ関数ドキュメント

const_iterator::const_iterator()

初期化されていないイテレータを構築します。

key()、value()、 operator++() などの関数を、初期化されていないイテレータで呼び出してはいけません。operator=() を使用して値を代入してから使用してください。

QMultiMap::constBegin() およびQMultiMap::constEnd()も参照してください

const_iterator::const_iterator(const QMultiMap<Key, T>::iterator &other)

other のコピーを作成する。

const Key &const_iterator::key() const

現在のアイテムのキーを返します。

value()も参照

const T &const_iterator::value() const

現在の項目の値を返します。

key() およびoperator*()も参照

const T &const_iterator::operator*() const

現在の項目の値を返します。

value() と同じ。

key()も参照

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

前置演算子++ (++i) は、イテレータをマップの次の項目に進め、新しい現在の項目へのイテレータを返す。

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

operator--()も参照

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

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

postfix++ 演算子(i++)は、イテレータをマップの次の項目に進め、それ以前の現在の項目へのイテレータを返します。

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

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

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

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

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

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

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

const T *const_iterator::operator->() const

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

value()も参照

関連する非会員

bool operator==(const QMultiMap<Key, T>::const_iterator &lhs, const QMultiMap<Key, T>::const_iterator &rhs)

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

operator!=()も参照のこと

bool operator!=(const QMultiMap<Key, T>::const_iterator &lhs, const QMultiMap<Key, T>::const_iterator &rhs)

lhs がイテレータrhs と異なる項目を指している場合は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.