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<키, 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 is QSet<QString>::const_iteratorfor(auto i = 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=()를 사용하여 값을 할당하세요.
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.