QLinkedList::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 を変更する必要がない限り、非constの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)
後置の ++ 演算子(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)
ポストフィックス演算子(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!=()も参照してください 。
© 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.