이 페이지에서

QMultiMap::const_iterator Class

class QMultiMap::const_iterator

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

공개 유형

공개 함수

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

상세 설명

QMultiMap<Key, T>::const_iterator를 사용하면 QMultiMap 를 반복 처리할 수 있습니다. 반복 처리하는 동안 QMultiMap 를 수정하려면 대신 QMultiMap::iterator 를 사용해야 합니다. 이터레이터를 통해 ` QMultiMap `을 변경해야 하는 경우가 아니라면, 일반적으로 ` QMultiMap::const_iterator `을 `non-const` ` QMultiMap `에 사용하는 것이 권장됩니다. `const` 이터레이터는 속도가 약간 더 빠르며, 코드의 가독성을 높일 수 있습니다.

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

QMultiMap<QString, int> multimap;
multimap.insert("January", 1);
multimap.insert("February", 2);
//...
multimap.insert("December", 12);

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

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

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

항목을 임의의 순서로 저장하는 QMultiHash 와 달리, QMultiMap 는 키 순서대로 항목을 저장합니다. 동일한 키를 가진 항목들은 가장 최근에 삽입된 값부터 가장 오래전에 삽입된 값 순으로 연속적으로 나타납니다.

동일한 멀티 맵에서 여러 개의 이터레이터를 사용할 수 있습니다. 맵에 항목을 추가하더라도 기존 이터레이터는 유효한 상태를 유지합니다. 맵에서 항목을 제거하면, 제거된 항목을 가리키던 이터레이터는 더 이상 유효하지 않은 이터레이터(dangling iterator)가 됩니다.

경고: 암시적으로 공유되는 컨테이너의이터레이터는 STL 이터레이터와 정확히 동일하게 작동하지 않습니다. 해당 컨테이너에 이터레이터가 활성화된 상태에서는 컨테이너를 복사하지 않도록 해야 합니다. 자세한 내용은 ‘암시적 공유 이터레이터 문제’를 참조하십시오.

QMultiMap::iterator, QMultiMap::key_iterator, QMultiMap::const_key_value_iterator도 참조하십시오 .

멤버 유형 설명서

[alias] const_iterator::iterator_category

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

멤버 함수 설명서

[default] const_iterator::const_iterator()

초기화되지 않은 반복자를 생성합니다.

key(), value() 및 operator++()와 같은 함수는 초기화되지 않은 반복자에 대해 호출해서는 안 됩니다. 사용하기 전에 operator=()를 사용하여 값을 할당하십시오.

QMultiMap::constBegin() 및 QMultiMap::constEnd()도 참조하십시오 .

const_iterator::const_iterator(const QMultiMap<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()도 참조하십시오 .

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

++ 연산자(++i)는 이터레이터를 맵의 다음 항목으로 이동시키고, 새로운 현재 항목에 대한 이터레이터를 반환합니다.

QMultiMap::end()에서 이 함수를 호출하면 정의되지 않은 결과가 발생합니다.

operator--()도 참조하십시오 .

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

후치 연산자 ` ++ `(i++)는 이터레이터를 맵의 다음 항목으로 이동시키고, 이전에 선택되어 있던 항목에 대한 이터레이터를 반환합니다.

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

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

-- 연산자(--i)는 앞의 항목을 현재 항목으로 설정하고, 새로운 현재 항목을 가리키는 이터레이터를 반환합니다.

QMultiMap::begin()에 대해 이 함수를 호출하면 정의되지 않은 결과가 발생합니다.

operator++()도 참조하십시오 .

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

후치 연산자 ` -- `(i--)는 바로 앞의 항목을 현재 항목으로 지정하고, 이전에 현재 항목이었던 항목을 가리키는 이터레이터를 반환합니다.

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

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

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

value()도 참조하십시오 .

관련 비멤버 함수

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

lhs 가 rhs 이터레이터와 다른 항목을 가리키는 경우 true 를 반환하고, 그렇지 않은 경우 false 를 반환합니다.

operator==()도 참조하십시오 .

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

lhs 가 rhs 반복자가 가리키는 항목과 동일한 항목을 가리키는 경우 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.