このページでは

QMultiMap::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 を変更する必要がない限り、非constのQMultiMap に対してもQMultiMap::const_iterator を使用するのが一般的なベストプラクティスです。constイテレータはわずかに高速であり、コードの可読性を高めることができます。

デフォルトのQMultiMap::const_iterator コンストラクタは、初期化されていないイテレータを作成します。反復処理を開始する前に、QMultiMap::cbegin()、QMultiMap::cend()、またはQMultiMap::constFind()などのQMultiMap 関数を使用して、イテレータを初期化する必要があります。以下は、マップに格納されているすべての(key, value)ペアを出力する典型的なループです:

QMultiMap<QString, int> multimap;
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::iterator 、QMultiMap::key_iterator 、およびQMultiMap::const_key_value_iterator 。

メンバ型のドキュメント

[alias] const_iterator::iterator_category

このイテレータが双方向イテレータであることを示す、std::bidirectional_iterator_tagの同義語。

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

[default] 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)

後置演算子 `++ ` (i++) は、イテレータをマップ内の次の項目に進め、直前に現在位置にあった項目へのイテレータを返します。

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

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

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

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

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

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

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

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

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

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

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

関連する非メンバー関数

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

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

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

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

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