const_iterator Class
class QMultiHash::const_iteratorQMultiHash::const_iterator クラスは、QMultiHash 用の STL スタイルの const イテレータを提供します。詳細...
パブリック関数
const_iterator() | |
const_iterator(const QMultiHash<Key, T>::iterator &other) | |
const Key & | key() const |
T & | value() const |
bool | operator!=(const QMultiHash<Key, T>::const_iterator &other) const |
T & | operator*() const |
QMultiHash<Key, T>::const_iterator & | operator++() |
QMultiHash<Key, T>::const_iterator | operator++(int) |
T * | operator->() const |
bool | operator==(const QMultiHash<Key, T>::const_iterator &other) const |
詳しい説明
QMultiHash<Key, T>::const_iterator を使うと、QMultiHash を繰り返し処理できます。QMultiHash を繰り返し処理しながら変更したい場合は、代わりにQMultiHash::iterator を使う必要があります。イテレータを通してQMultiHash を変更する必要がない限り、constQMultiHash 以外でもQMultiHash::const_iterator を使用するのが一般的です。constイテレータの方が若干高速で、コードの可読性も向上します。
デフォルトのQMultiHash::const_iterator コンストラクタは、初期化されていないイテレータを作成します。QMultiHash::cbegin ()、QMultiHash::cend ()、QMultiHash::constFind ()のようなQMultiHash 関数を使用して初期化しなければなりません。以下は、ハッシュに格納されたすべての(キー、値)ペアを表示する典型的なループです:
QHash<QString, int> hash; hash.insert("January", 1); hash.insert("February", 2); ... hash.insert("December", 12); for (auto i = hash.cbegin(), end = hash.cend(); i != end; ++i) cout << qPrintable(i.key()) << ": " << i.value() << endl;
QMap 、項目をキー順に並べるのとは異なり、QMultiHash 、項目は任意の順序で格納される。唯一の保証は、(QMultiHash を使って挿入されたため)同じキーを共有する項目は、最も最近に挿入された値から最も最近に挿入された値まで、連続して表示されるということである。
同じハッシュに対して複数のイテレータを使用することができる。しかし、QMultiHash (項目の挿入や削除) を直接変更すると、イテレータが無効になる可能性があることに注意してください。
ハッシュに項目を挿入したり、QMultiHash::reserve() や QMultiHash::squeeze() などのメソッドを呼び出したりすると、ハッシュを指すすべてのイテレータが無効になる可能性があります。イテレータは、QMultiHash が内部ハッシュテーブルを増やしたり縮めたりする必要がない限り、有効であり続けることが保証されています。再ハッシュ操作が発生した後にイテレータを使用すると、未定義の動作につながります。
長期間イテレータを保持する必要がある場合は、QMultiHash ではなくQMultiMap を使用することをお勧めします。
警告 暗黙的に共有されたコンテナ上のイテレータは、STLイテレータのようには動作しません。そのコンテナ上でイテレータがアクティブになっている間は、コンテナのコピーを避けるべきである。詳細については、暗黙的共有イテレータ問題を参照してください。
QMultiHash::iterator 、QMultiHash::key_iterator 、QMultiHash::const_key_value_iteratorも参照のこと 。
メンバ関数ドキュメント
[constexpr noexcept]
const_iterator::const_iterator()
初期化されていないイテレータを構築します。
key()、value()、 operator++() などの関数を、初期化されていないイテレータで呼び出してはいけません。operator=() を使用して値を代入してから使用してください。
QMultiHash::constBegin() およびQMultiHash::constEnd()も参照してください 。
[noexcept]
const_iterator::const_iterator(const QMultiHash<Key, T>::iterator &other)
other のコピーを作成する。
[noexcept]
const Key &const_iterator::key() const
現在のアイテムのキーを返します。
value()も参照 。
[noexcept]
T &const_iterator::value() const
現在の項目の値を返します。
[noexcept]
bool const_iterator::operator!=(const QMultiHash<Key, T>::const_iterator &other) const
other がこのイテレータとは異なるアイテムを指している場合はtrue
を返し、そうでない場合はfalse
を返す。
operator==()も参照 。
[noexcept]
T &const_iterator::operator*() const
現在の項目の値を返します。
value() と同じ。
key()も参照 。
[noexcept]
QMultiHash<Key, T>::const_iterator &const_iterator::operator++()
接頭辞 ++ 演算子 (++i
) は、イテレータをハッシュの次の項目に進め、新しい現在の項目へのイテレータを返します。
この関数をQMultiHash::end() で呼び出すと、未定義の結果になります。
[noexcept]
QMultiHash<Key, T>::const_iterator const_iterator::operator++(int)
これはオーバーロードされた関数です。
ポストフィックス ++ 演算子 (i++
) は、イテレータをハッシュの次の項目に進め、それ以前の現在の項目へのイテレータを返します。
[noexcept]
T *const_iterator::operator->() const
現在の項目の値へのポインタを返します。
value()も参照 。
[noexcept]
bool const_iterator::operator==(const QMultiHash<Key, T>::const_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.