std::unordered_map<Key,T,Hash,KeyEqual,Allocator>:: begin, std::unordered_map<Key,T,Hash,KeyEqual,Allocator>:: cbegin
From cppreference.net
<
cpp
|
container
|
unordered map
|
iterator begin
(
)
noexcept
;
|
(1) |
(C++11부터)
(C++26부터 constexpr) |
|
const_iterator begin
(
)
const
noexcept
;
|
(2) |
(C++11부터)
(C++26부터 constexpr) |
|
const_iterator cbegin
(
)
const
noexcept
;
|
(3) |
(C++11부터)
(C++26부터 constexpr) |
* this 의 첫 번째 요소에 대한 반복자를 반환합니다.
만약 * this 가 비어있는 경우, 반환된 반복자는 end() 와 같을 것입니다.
목차 |
반환값
첫 번째 요소에 대한 반복자.
복잡도
상수.
예제
이 코드 실행
#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) |