const_iterator Class

class QMap::const_iterator

QMap::const_iterator 클래스는 QMap 에 대한 STL 스타일 const 이터레이터를 제공합니다. 더 보기...

공용 유형

공용 함수

const_iterator()
const_iterator(const QMap<Key, T>::iterator &other)
const Key &key() const
const T &value() const
const T &operator*() const
QMap<Key, T>::const_iterator &operator++()
QMap<Key, T>::const_iterator operator++(int)
QMap<Key, T>::const_iterator &operator--()
QMap<Key, T>::const_iterator operator--(int)
const T *operator->() const
bool operator!=(const QMap<Key, T>::const_iterator &lhs, const QMap<Key, T>::const_iterator &rhs)
bool operator==(const QMap<Key, T>::const_iterator &lhs, const QMap<Key, T>::const_iterator &rhs)

상세 설명

QMap<키, T>::const_iterator를 사용하면 QMap 를 반복할 수 있습니다. 반복하면서 QMap 을 수정하려면 QMap::iterator 을 대신 사용해야 합니다. 일반적으로 이터레이터를 통해 QMap 을 변경해야 하는 경우가 아니라면, const가 아닌 QMap 에도 QMap::const_iterator 을 사용하는 것이 좋습니다. Const 이터레이터는 약간 더 빠르며 코드 가독성을 향상시킬 수 있습니다.

기본 QMap::const_iterator 생성자는 초기화되지 않은 이터레이터를 생성합니다. QMap::cbegin (), QMap::cend() 또는 QMap::constFind()와 같은 QMap 함수를 사용하여 초기화해야 반복을 시작할 수 있습니다. 다음은 맵에 저장된 모든 (키, 값) 쌍을 인쇄하는 일반적인 루프입니다:

QMap<QString, int> map;
map.insert("January", 1);
map.insert("February", 2);
...
map.insert("December", 12);

for (auto i = map.cbegin(), end = map.cend(); i != end; ++i)
    cout << qPrintable(i.key()) << ": " << i.value() << endl;

다음은 값이 10보다 큰 모든 항목을 제거하는 예제입니다:

QMap<QString, int>::const_iterator i = map.cbegin();
while (i != map.cend()) {
    if (i.value() > 10)
        i = map.erase(i);
    else
        ++i;
}

다음은 erase_if()의 동일한 동작입니다.

erase_if(map, [](const QMap<QString, int>::iterator it) { return it.value() > 10; });

임의의 순서로 항목을 저장하는 QHash 과 달리 QMap 은 키별로 정렬된 항목을 저장합니다.

동일한 맵에서 여러 개의 반복자를 사용할 수 있습니다. 맵에 항목을 추가하면 기존 반복자는 유효하게 유지됩니다. 맵에서 항목을 제거하면 제거된 항목을 가리키는 반복자는 매달린 반복자가 됩니다.

경고: 암시적으로 공유되는 컨테이너의 반복기는 STL 반복기와 똑같이 작동하지 않습니다. 해당 컨테이너에서 이터레이터가 활성화되어 있는 동안에는 컨테이너를 복사하지 않아야 합니다. 자세한 내용은 암시적 공유 반복자 문제를 참조하세요.

QMap::iterator, QMap::key_iterator, QMap::const_key_value_iterator도 참조하세요 .

멤버 유형 문서

[alias] const_iterator::iterator_category

이 이터레이터가 양방향 이터레이터임을 나타내는 std::bidirectional_iterator_tag의 동의어입니다.

멤버 함수 문서

const_iterator::const_iterator()

초기화되지 않은 이터레이터를 생성합니다.

key(), value(), operator++() 같은 함수는 초기화되지 않은 이터레이터에서 호출해서는 안 됩니다. 사용하기 전에 operator=()를 사용하여 값을 할당하세요.

QMap::constBegin() 및 QMap::constEnd()도 참조하세요 .

const_iterator::const_iterator(const QMap<Key, T>::iterator &other)

other 의 복사본을 생성합니다.

const Key &const_iterator::key() const

현재 항목의 키를 반환합니다.

value()도 참조하세요 .

const T &const_iterator::value() const

현재 항목의 값을 반환합니다.

key() 및 operator*()도 참조하세요 .

const T &const_iterator::operator*() const

현재 항목의 값을 반환합니다.

value()와 동일합니다.

key()도 참조하세요 .

QMap<Key, T>::const_iterator &const_iterator::operator++()

접두사 ++ 연산자(++i)는 반복자를 맵의 다음 항목으로 전진시키고 반복자를 새 현재 항목으로 반환합니다.

QMap::end()에서 이 함수를 호출하면 정의되지 않은 결과가 나타납니다.

operator--()도 참조하세요 .

QMap<Key, T>::const_iterator const_iterator::operator++(int)

이 함수는 오버로드된 함수입니다.

후위 ++ 연산자(i++)는 반복기를 맵의 다음 항목으로 전진시키고 반복기를 이전 현재 항목으로 반환합니다.

QMap<Key, T>::const_iterator &const_iterator::operator--()

접두사 -- 연산자(--i)는 이전 항목을 현재 항목으로 만들고 새 현재 항목을 가리키는 이터레이터를 반환합니다.

QMap::begin()에서 이 함수를 호출하면 정의되지 않은 결과가 나타납니다.

operator++()도 참조하세요 .

QMap<Key, T>::const_iterator const_iterator::operator--(int)

이 함수는 오버로드된 함수입니다.

후위 -- 연산자(i--)는 이전 항목을 현재 항목으로 만들고 이전 현재 항목을 가리키는 반복자를 반환합니다.

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

현재 항목의 값에 대한 포인터를 반환합니다.

value()도 참조하세요 .

관련 비회원

bool operator==(const QMap<Key, T>::const_iterator &lhs, const QMap<Key, T>::const_iterator &rhs)

lhsrhs 이터레이터와 동일한 항목을 가리키면 true 을 반환하고, 그렇지 않으면 false 을 반환합니다.

operator!=()도 참조하세요 .

bool operator!=(const QMap<Key, T>::const_iterator &lhs, const QMap<Key, T>::const_iterator &rhs)

lhsrhs 이터레이터와 다른 항목을 가리키면 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.