const_iterator Class
class QLinkedList::const_iteratorQLinkedList::const_iterator クラスは、QLinkedList 用の STL スタイルの const イテレータを提供します。詳細...
パブリック関数
const_iterator() | |
const_iterator(QLinkedList<T>::iterator other) | |
bool | operator!=(const QLinkedList<T>::const_iterator &other) const |
const T & | operator*() const |
QLinkedList<T>::const_iterator | operator+(int j) const |
QLinkedList<T>::const_iterator & | operator++() |
QLinkedList<T>::const_iterator | operator++(int) |
QLinkedList<T>::const_iterator & | operator+=(int j) |
QLinkedList<T>::const_iterator | operator-(int j) const |
QLinkedList<T>::const_iterator & | operator--() |
QLinkedList<T>::const_iterator | operator--(int) |
QLinkedList<T>::const_iterator & | operator-=(int j) |
const T * | operator->() const |
bool | operator==(const QLinkedList<T>::const_iterator &other) const |
詳細説明
QLinkedList は、STLスタイルのイテレータと Javaスタイルのイテレータの両方を備えています。STLスタイルのイテレータは、より低レベルで使い方が面倒ですが、その反面、若干高速で、すでにSTLを知っている開発者にとっては親しみやすいという利点があります。
QLinkedList<T>::const_iterator を使うと、QLinkedList<T> を反復処理できます。QLinkedList を繰り返しながら変更したい場合は、QLinkedList::iterator を使用する必要があります。イテレータを通してQLinkedList を変更する必要がない限り、QLinkedList にQLinkedList::const_iterator を使用するのが一般的です。constイテレータの方が若干高速で、コードの可読性も向上します。
デフォルトのQLinkedList::const_iterator コンストラクタは、初期化されていないイテレータを作成します。QLinkedList::constBegin ()、QLinkedList::constEnd ()、QLinkedList::insert ()のような関数を使用して初期化しなければなりません。以下は、リストに格納されたすべての項目を表示する典型的なループです:
QLinkedList<QString> list; list.append("January"); list.append("February"); ... list.append("December"); QLinkedList<QString>::const_iterator i; for (i = list.constBegin(); i != list.constEnd(); ++i) cout << *i << Qt::endl;
STLスタイルのイテレータは、generic algorithms の引数として使用できます。例えば、リスト内の項目を見つける方法です:
QLinkedList<QString> list; ... QLinkedList<QString>::const_iterator it = std::find(list.constBegin(), list.constEnd(), "Joel"); if (it != list.constEnd()) cout << "Found Joel" << Qt::endl;
同じリストに対して複数のイテレータを使用することができます。リストに項目を追加しても、既存のイテレータは有効なままです。リストから項目を削除すると、削除された項目を指すイテレータはダングリング・イテレータになります。
警告 暗黙的に共有されたコンテナ上のイテレータは、STLイテレータのようには動作しません。そのコンテナ上でイテレータがアクティブになっている間は、コンテナのコピーを避けるべきである。詳細については、暗黙の共有イテレータ問題を参照してください。
QLinkedList::iterator およびQLinkedListIteratorも参照のこと 。
メンバ関数ドキュメント
const_iterator::const_iterator()
初期化されていないイテレータを構築します。
operator*() や operator++() のような関数を、初期化されていないイテレータに対して呼び出してはいけません。operator=() を使用して値を代入してから使用してください。
QLinkedList::constBegin() およびQLinkedList::constEnd()も参照してください 。
const_iterator::const_iterator(QLinkedList<T>::iterator other)
other のコピーを作成する。
bool const_iterator::operator!=(const QLinkedList<T>::const_iterator &other) const
other がこのイテレータとは異なるアイテムを指している場合はtrue
を返し、そうでない場合はfalse
を返す。
operator==()も参照 。
const T &const_iterator::operator*() const
現在の項目への参照を返します。
operator->()も参照 。
QLinkedList<T>::const_iterator const_iterator::operator+(int j) const
このイテレータからj 前方の位置のアイテムへのイテレータを返します。(j が負の場合、イテレータは後方に進みます)。
この操作は、j の値が大きい場合に遅くなることがあります。
operator-()も参照 。
QLinkedList<T>::const_iterator &const_iterator::operator++()
接頭辞 ++ 演算子 (++it
) は、イテレータをリストの次の項目に進め、新しい現在の項目へのイテレータを返します。
QLinkedList<T>::constEnd() でこの関数を呼び出すと、未定義の結果になります。
operator--()も参照してください 。
QLinkedList<T>::const_iterator const_iterator::operator++(int)
これはオーバーロードされた関数である。
postfix ++ 演算子 (it++
) は、イテレータをリストの次の項目に進め、それ以前の現在の項目へのイテレータを返します。
QLinkedList<T>::const_iterator &const_iterator::operator+=(int j)
イテレータをj アイテム分進めます。(j が負の場合、イテレータは後退する)。
この操作は、j の値が大きい場合に遅くなることがあります。
operator-=() およびoperator+()も参照のこと 。
QLinkedList<T>::const_iterator const_iterator::operator-(int j) const
この関数は、このイテレータからj 後方の位置のアイテムへのイテレータを返します。(j が負の場合、イテレータは前方に進みます)。
この操作は、j の値が大きい場合に遅くなることがあります。
operator+()も参照 。
QLinkedList<T>::const_iterator &const_iterator::operator--()
接頭辞 - 演算子 (--it
) は、直前の項目を現在の項目にし、新しい現在の項目へのイテレータを返します。
この関数をQLinkedList::begin() で呼び出すと、未定義の結果になります。
operator++()も参照 。
QLinkedList<T>::const_iterator const_iterator::operator--(int)
これはオーバーロードされた関数である。
postfix - 演算子 (it--
) は、直前の項目をカレントにし、直前の項目へのイテレータを返します。
QLinkedList<T>::const_iterator &const_iterator::operator-=(int j)
イテレータをj アイテム分戻します。(j が負の場合、イテレータは前に進みます)。
この操作は、j の値が大きい場合に遅くなることがある。
operator+=() およびoperator-()も参照のこと 。
const T *const_iterator::operator->() const
現在の項目へのポインタを返します。
operator*()も参照 。
bool const_iterator::operator==(const QLinkedList<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.