const_iterator Class

class QSet::const_iterator

QSet::const_iterator クラスは、QSet 用の STL スタイルの const イテレータを提供します。さらに...

パブリック型

パブリック関数

const_iterator()
const_iterator(const QSet<T>::iterator &other)
const_iterator(const QSet<T>::const_iterator &other)
bool operator!=(const QSet<T>::const_iterator &other) const
const T &operator*() const
QSet<T>::const_iterator &operator++()
QSet<T>::const_iterator operator++(int)
const T *operator->() const
QSet<T>::const_iterator &operator=(const QSet<T>::const_iterator &other)
bool operator==(const QSet<T>::const_iterator &other) const

詳細説明

QSet には、STLスタイルのイテレータと Javaスタイルのイテレータの両方が用意されている。STLスタイルのイテレータはより低レベルで使い方が面倒だが、その反面、若干高速で、すでにSTLを知っている開発者にとっては親しみやすいという利点がある。

QSet<Key, T>::const_iterator を使うと、QSet を繰り返し処理できます。QSet を繰り返し処理しながら変更したい場合は、QSet::iterator を代わりに使う必要があります。イテレータを通してQSet を変更する必要がない限り、constQSet 以外でもQSet::const_iterator を使用するのが一般的です。constイテレータの方が若干高速で、コードの可読性も向上します。

デフォルトのQSet::const_iterator コンストラクタは、初期化されていないイテレータを作成します。QSet::begin ()、QSet::end ()、QSet::insert ()のような関数を使用して初期化しなければなりません。以下は、セットに格納されているすべての項目を表示する典型的なループです:

QSet<QString> set={"January", "February", ... "December"};// i is QSet<QString>::const_iteratorfor(autoi=set.cbegin(),end=set.cend(); i!=end;++i)    qDebug() << *i;

STLスタイルのイテレータは、generic algorithms の引数として使用できる。例えば、qFind() アルゴリズムを使用してセット内の項目を見つける方法を示します:

QSet<QString> set;
...
const auto predicate = [](const QString &s) { return s.compare("Jeanette", Qt::CaseInsensitive) == 0; };
QSet<QString>::const_iterator it = std::find_if(set.cbegin(), set.cend(), predicate);
if (it != set.constEnd())
    cout << "Found Jeanette" << endl;

警告: 警告: 暗黙的に共有されたコンテナ上のイテレータは、STLイテレータのようには動作しません。コンテナ上でイテレータがアクティブになっている間は、コンテナのコピーを避ける必要があります。詳細については、暗黙の共有イテレータ問題を参照してください。

QSet::iterator およびQSetIteratorも参照のこと

メンバ型ドキュメント

const_iterator::iterator_category

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

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

const_iterator::const_iterator()

初期化されていないイテレータを構築します。

operator*() や operator++() のような関数を、初期化されていないイテレータに対して呼び出してはいけません。operator=() を使用して値を代入してから使用してください。

QSet::begin() およびQSet::end()も参照してください

const_iterator::const_iterator(const QSet<T>::const_iterator &other)

other のコピーを作成する。

QSet<T>::const_iterator &const_iterator::operator=(const QSet<T>::const_iterator &other)

このイテレータにother を割り当てます。

const T &const_iterator::operator*() const

現在の項目への参照を返します。

operator->()も参照

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

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

operator*()も参照

bool const_iterator::operator==(const QSet<T>::const_iterator &other) const

other がこのイテレータと同じアイテムを指している場合はtrue を返し、そうでない場合はfalse を返す。

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

bool const_iterator::operator!=(const QSet<T>::const_iterator &other) const

other がこのイテレータとは異なるアイテムを指している場合はtrue を返し、そうでない場合はfalse を返す。

operator==()も参照

QSet<T>::const_iterator &const_iterator::operator++()

接頭辞 ++ 演算子 (++it) は、イテレータをセットの次のアイテムに進め、新しい現在のアイテムへのイテレータを返します。

QSet<T>::constEnd() でこの関数を呼び出すと、未定義の結果になります。

QSet<T>::const_iterator const_iterator::operator++(int)

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

ポストフィックス ++ 演算子 (it++) は、イテレータをセットの次のアイテムに進め、それ以前の現在のアイテムへのイテレータを返します。

const_iterator::const_iterator(const QSet<T>::iterator &other)

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

other のコピーを作成する。

© 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.