Namespaces
Variants

std::unordered_map<Key,T,Hash,KeyEqual,Allocator>:: end, std::unordered_map<Key,T,Hash,KeyEqual,Allocator>:: cend

From cppreference.net

iterator end ( ) noexcept ;
(1) (C++11부터)
(C++26부터 constexpr)
const_iterator end ( ) const noexcept ;
(2) (C++11부터)
(C++26부터 constexpr)
const_iterator cend ( ) const noexcept ;
(3) (C++11부터)
(C++26부터 constexpr)

* this 의 마지막 요소 바로 다음을 가리키는 반복자를 반환합니다.

이 반환된 반복자는 단지 센티넬 역할만 합니다. 이것이 dereferenceable 하다는 보장은 없습니다.

range-begin-end.svg

목차

반환값

마지막 요소의 다음을 가리키는 반복자.

복잡도

상수.

예제

#include <cmath>
#include <iostream>
#include <unordered_map>
struct Node { double x, y; };
int main()
{
    Node nodes[3] = {{1, 0}, {2, 0}, {3, 0}};
    // mag는 Node의 주소를 평면에서의 크기에 매핑하는 맵입니다
    std::unordered_map<Node*, double> mag =
    {
        { nodes + 0, 1 },
        { nodes + 1, 2 },
        { nodes + 2, 3 }
    };
    // 각 y좌표를 0에서 크기 값으로 변경
    for (auto iter = mag.begin(); iter != mag.end(); ++iter)
    {
        auto cur = iter->first; // Node에 대한 포인터
        cur->y = mag[cur]; // cur->y = iter->second;도 사용 가능
    }
    // 각 노드의 크기를 업데이트하고 출력
    for (auto iter = mag.begin(); iter != mag.end(); ++iter)
    {
        auto cur = iter->first;
        mag[cur] = std::hypot(cur->x, cur->y);
        std::cout << "The magnitude of (" << cur->x << ", " << cur->y << ") is ";
        std::cout << iter->second << '\n';
    }
    // 범위 기반 for 루프로 위 과정 반복
    for (auto i : mag)
    {
        auto cur = i.first;
        cur->y = i.second;
        mag[cur] = std::hypot(cur->x, cur->y);
        std::cout << "The magnitude of (" << cur->x << ", " << cur->y << ") is ";
        std::cout << mag[cur] << '\n';
        // 위의 std::cout << iter->second << '\n';과 달리
        // std::cout << i.second << '\n';은 업데이트된 크기를 출력하지 않습니다
    }
}

가능한 출력:

The magnitude of (3, 3) is 4.24264
The magnitude of (1, 1) is 1.41421
The magnitude of (2, 2) is 2.82843
The magnitude of (3, 4.24264) is 5.19615
The magnitude of (1, 1.41421) is 1.73205
The magnitude of (2, 2.82843) is 3.4641

참고 항목

시작 부분에 대한 반복자를 반환함
(public member function)
(C++11) (C++14)
컨테이너나 배열의 끝 부분에 대한 반복자를 반환함
(function template)