const_iterator Class
class QMap::const_iteratorQMap::const_iterator クラスは、QMap 用の STL スタイルの const イテレータを提供します。詳細...
パブリック型
パブリック関数
const_iterator() | |
const_iterator(const QMap<Key, T>::iterator &other) | |
const Key & | key() const |
const T & | value() const |
const T & | operator*() const |
QMap<Key, T>::const_iterator & | operator++() |
QMap<Key, T>::const_iterator | operator++(int) |
QMap<Key, T>::const_iterator & | operator--() |
QMap<Key, T>::const_iterator | operator--(int) |
const T * | operator->() const |
関連する非メンバー
bool | operator!=(const QMap<Key, T>::const_iterator &lhs, const QMap<Key, T>::const_iterator &rhs) |
bool | operator==(const QMap<Key, T>::const_iterator &lhs, const QMap<Key, T>::const_iterator &rhs) |
詳しい説明
QMap<Key, T>::const_iterator を使うと、QMap を繰り返し処理できます。QMap を繰り返し処理しながら変更したい場合は、代わりにQMap::iterator を使う必要があります。イテレータを通してQMap を変更する必要がない限り、constQMap 以外でもQMap::const_iterator を使用するのが一般的です。constイテレータの方が若干高速で、コードの可読性も向上します。
デフォルトのQMap::const_iterator コンストラクタは、初期化されていないイテレータを作成します。QMap::cbegin ()、QMap::cend ()、QMap::constFind ()のようなQMap 関数を使用して初期化しなければなりません。以下は、マップに格納されたすべての(キー、値)ペアを表示する典型的なループです:
QMap<QString, int> map; map.insert("January", 1); map.insert("February", 2); ... map.insert("December", 12); for (auto i = map.cbegin(), end = map.cend(); i != end; ++i) cout << qPrintable(i.key()) << ": " << i.value() << endl;
以下は、値が10より大きい項目をすべて削除する例である:
QMap<QString, int>::const_iterator i = map.cbegin(); while (i != map.cend()) { if (i.value() > 10) i = map.erase(i); else ++i; }
また、erase_if ()でも同じ動作をします。
項目を任意の順序で格納するQHash とは異なり、QMap は項目をキー順に格納します。
同じマップに対して複数のイテレータを使用することができる。マップに項目を追加しても、既存のイテレータは有効なままです。マップから項目を削除すると、削除された項目を指すイテレータはぶら下がったイテレータになります。
警告 暗黙的に共有されたコンテナ上のイテレータは、STLイテレータのようには動作しません。そのコンテナ上でイテレータがアクティブになっている間は、コンテナのコピーを避けるべきです。詳細については、暗黙的共有イテレータ問題を参照してください。
QMap::iterator 、QMap::key_iterator 、QMap::const_key_value_iteratorも参照のこと 。
メンバ型ドキュメント
[alias]
const_iterator::iterator_category
このイテレータが双方向イテレータであることを示すstd::bidirectional_iterator_tagのシノニム。
メンバ関数ドキュメント
const_iterator::const_iterator()
初期化されていないイテレータを構築します。
key()、value()、 operator++() などの関数を、初期化されていないイテレータで呼び出してはいけません。operator=() を使用して値を代入してから使用してください。
QMap::constBegin() およびQMap::constEnd()も参照してください 。
const_iterator::const_iterator(const QMap<Key, T>::iterator &other)
other のコピーを作成する。
const Key &const_iterator::key() const
現在のアイテムのキーを返します。
value()も参照 。
const T &const_iterator::value() const
現在の項目の値を返します。
const T &const_iterator::operator*() const
現在の項目の値を返します。
value() と同じ。
key()も参照 。
QMap<Key, T>::const_iterator &const_iterator::operator++()
前置演算子++
(++i
) は、イテレータをマップの次の項目に進め、新しい現在の項目へのイテレータを返す。
この関数をQMap::end() で呼び出すと、未定義の結果になります。
operator--()も参照 。
QMap<Key, T>::const_iterator const_iterator::operator++(int)
これはオーバーロードされた関数である。
postfix++
演算子(i++
)は、イテレータをマップの次の項目に進め、それ以前の現在の項目へのイテレータを返します。
QMap<Key, T>::const_iterator &const_iterator::operator--()
前置演算子--
(--i
) は、直前の項目をカレントにし、新しいカレント項目を指すイテレータを返す。
この関数をQMap::begin() で呼び出すと、未定義の結果になります。
operator++()も参照してください 。
QMap<Key, T>::const_iterator const_iterator::operator--(int)
これはオーバーロードされた関数である。
postfix--
演算子(i--
)は、直前の項目をカレントとし、直前の項目を指すイテレータを返します。
const T *const_iterator::operator->() const
現在の項目の値へのポインタを返します。
value()も参照 。
関連する非会員
bool operator==(const QMap<Key, T>::const_iterator &lhs, const QMap<Key, T>::const_iterator &rhs)
lhs がrhs イテレータと同じ項目を指している場合はtrue
を返し、そうでない場合はfalse
を返す。
operator!=()も参照のこと 。
bool operator!=(const QMap<Key, T>::const_iterator &lhs, const QMap<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.