QSet::const_iterator Class
class QSet::const_iteratorQSet::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 を変更する必要がない限り、非constのQSet に対してもQSet::const_iterator を使用するのが一般的なベストプラクティスです。constイテレータはわずかに高速であり、コードの可読性を向上させることができます。
デフォルトのQSet::const_iterator コンストラクタは、初期化されていないイテレータを作成します。反復処理を開始する前に、QSet::begin()、QSet::end()、またはQSet::insert() などの関数を使用して、イテレータを初期化する必要があります。以下は、セットに格納されているすべての項目を出力する典型的なループです:
QSet<QString>set={"January", "February", /*...*/ "December"};
// i は QSet<QString>::const_iterator です
for(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>::iterator &other)
other のコピーを作成します。
これはオーバーロードされた関数です。
const_iterator::const_iterator(const QSet<T>::const_iterator &other)
other のコピーを作成します。
bool const_iterator::operator!=(const QSet<T>::const_iterator &other) const
other がこのイテレータとは異なる項目を指している場合はtrue を返し、そうでない場合はfalse を返します。
operator==()も参照してください 。
const T &const_iterator::operator*() const
現在の項目への参照を返します。
operator->()も参照してください 。
QSet<T>::const_iterator &const_iterator::operator++()
プレフィックス ++ 演算子(++it )は、イテレータをセット内の次の要素へと進め、新しい現在の要素へのイテレータを返します。
QSet<T>::constEnd() に対してこの関数を呼び出すと、未定義の結果となります。
QSet<T>::const_iterator const_iterator::operator++(int)
後置++演算子(it++ )は、イテレータをセット内の次の要素に進め、直前の要素へのイテレータを返します。
const T *const_iterator::operator->() const
現在の項目へのポインタを返します。
operator*()も参照してください 。
QSet<T>::const_iterator &const_iterator::operator=(const QSet<T>::const_iterator &other)
このイテレータにother を割り当てます。
bool const_iterator::operator==(const QSet<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.