std::map<Key,T,Compare,Allocator>:: end, std::map<Key,T,Compare,Allocator>:: cend
From cppreference.net
|
iterator end
(
)
;
|
(1) |
(C++11부터 noexcept)
(C++26부터 constexpr) |
|
const_iterator end
(
)
const
;
|
(2) |
(C++11부터 noexcept)
(C++26부터 constexpr) |
|
const_iterator cend
(
)
const
noexcept
;
|
(3) |
(C++11부터)
(C++26부터 constexpr) |
* this 의 마지막 요소 바로 다음을 가리키는 반복자를 반환합니다.
이 반환된 반복자는 단지 센티넬 역할만 합니다. 이것이 dereferenceable 하다는 보장은 없습니다.
목차 |
반환값
마지막 요소의 다음을 가리키는 반복자.
복잡도
상수.
참고 사항
libc++ 백포트는
cend()
를 C++98 모드로 지원합니다.
예제
이 코드 실행
출력:
1, 1.09 4, 4.13 9, 9.24
사용자 정의 비교 함수를 사용하는 예제
이 코드 실행
#include <cmath> #include <iostream> #include <map> struct Point { double x, y; }; // 두 Point 포인터의 x 좌표를 비교합니다. struct PointCmp { bool operator()(const Point* lhs, const Point* rhs) const { return lhs->x < rhs->x; } }; int main() { // x 좌표가 순서와 다르게 배치되어 있지만, // 맵은 x 좌표가 증가하는 순서로 순회됩니다. Point points[3] = {{2, 0}, {1, 0}, {3, 0}}; // mag는 노드의 주소를 x-y 평면에서의 크기에 매핑하는 맵입니다. // 키가 Point에 대한 포인터이지만, 맵을 Point의 주소가 아닌 // 점들의 x 좌표로 정렬하려고 합니다. 이것은 PointCmp 클래스의 // 비교 메서드를 사용하여 수행됩니다. std::map<Point*, double, PointCmp> mag( {{points, 2}, {points + 1, 1}, {points + 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';은 업데이트된 크기를 출력하지 않습니다. // 대신 auto &i : mag를 사용했다면 업데이트된 크기를 출력할 것입니다. } }
출력:
The magnitude of (1, 1) is 1.41421 The magnitude of (2, 2) is 2.82843 The magnitude of (3, 3) is 4.24264 The magnitude of (1, 1.41421) is 1.73205 The magnitude of (2, 2.82843) is 3.4641 The magnitude of (3, 4.24264) is 5.19615
참고 항목
|
(C++11)
|
시작 부분에 대한 반복자를 반환함
(public member function) |
|
(C++11)
(C++14)
|
컨테이너나 배열의 끝 부분에 대한 반복자를 반환함
(function template) |