std::multimap<Key,T,Compare,Allocator>:: multimap
| (1) | ||
|
multimap
(
)
;
|
(C++11 이전) | |
|
multimap
(
)
:
multimap
(
Compare
(
)
)
{
}
|
(C++11 이후)
(C++26 이후 constexpr) |
|
|
explicit
multimap
(
const
Compare
&
comp,
const Allocator & alloc = Allocator ( ) ) ; |
(2) | (C++26부터 constexpr) |
|
explicit
multimap
(
const
Allocator
&
alloc
)
;
|
(3) |
(C++11부터)
(C++26부터 constexpr) |
|
template
<
class
InputIt
>
multimap
(
InputIt first, InputIt last,
|
(4) | (C++26부터 constexpr) |
|
template
<
class
InputIt
>
multimap
(
InputIt first, InputIt last,
|
(5) |
(C++14부터)
(C++26부터 constexpr) |
|
multimap
(
const
multimap
&
other
)
;
|
(6) | (C++26부터 constexpr) |
|
multimap
(
const
multimap
&
other,
const
Allocator
&
alloc
)
;
|
(7) |
(C++11 이후)
(C++26 이후 constexpr) |
|
multimap
(
multimap
&&
other
)
;
|
(8) |
(C++11부터)
(C++26부터 constexpr) |
|
multimap
(
multimap
&&
other,
const
Allocator
&
alloc
)
;
|
(9) |
(C++11부터)
(C++26부터 constexpr) |
|
multimap
(
std::
initializer_list
<
value_type
>
init,
const
Compare
&
comp
=
Compare
(
)
,
|
(10) |
(C++11부터)
(C++26부터 constexpr) |
|
multimap
(
std::
initializer_list
<
value_type
>
init,
const
Allocator
&
alloc
)
|
(11) |
(C++14부터)
(C++26부터 constexpr) |
|
template
<
container-compatible-range
<
value_type
>
R
>
multimap
(
std::
from_range_t
, R
&&
rg,
|
(12) |
(C++23부터)
(C++26부터 constexpr) |
|
template
<
container-compatible-range
<
value_type
>
R
>
multimap
(
std::
from_range_t
, R
&&
rg,
|
(13) |
(C++23부터)
(C++26부터 constexpr) |
다양한 데이터 소스로부터 새로운 컨테이너를 생성하며, 선택적으로 사용자가 제공한 할당자 alloc 또는 비교 함수 객체 comp 를 사용합니다.
[
first
,
last
)
.
[
first
,
last
)
가 유효한 범위가 아니라면, 동작은 정의되지 않습니다.
|
alloc
이 제공되지 않으면, allocator는
std::
allocator_traits
<
allocator_type
>
::
|
(C++11부터) |
|
클래스 템플릿 인수 추론
중에는 첫 번째 인수만 컨테이너의
|
(C++23부터) |
|
클래스 템플릿 인수 추론
동안에는 첫 번째 인수만 컨테이너의
|
(since C++23) |
목차 |
매개변수
| alloc | - | 이 컨테이너의 모든 메모리 할당에 사용할 할당자 |
| comp | - | 키의 모든 비교에 사용할 비교 함수 객체 |
| first, last | - | 복사할 요소들의 소스 범위 를 정의하는 반복자 쌍 |
| other | - | 컨테이너의 요소를 초기화하는 데 사용할 소스 컨테이너 |
| init | - | 컨테이너의 요소를 초기화하는 데 사용할 초기화자 리스트 |
| rg | - |
컨테이너 호환 범위
, 즉 요소들이
value_type
으로 변환 가능한
input_range
|
| 타입 요구사항 | ||
-
InputIt
는
LegacyInputIterator
요구사항을 충족해야 함
|
||
-
Compare
는
Compare
요구사항을 충족해야 함
|
||
-
Allocator
는
Allocator
요구사항을 충족해야 함
|
||
복잡도
[
first
,
last
)
가 이미
value_comp
(
)
로 정렬된 경우
N
에 선형입니다.
예외
Allocator::allocate
에 대한 호출은 예외를 발생시킬 수 있습니다.
참고 사항
컨테이너 이동 생성 후 (오버로드 ( 8,9 ) ), other 에 대한 참조, 포인터 및 반복자(end 반복자 제외)는 유효하게 유지되지만, 이제는 * this 에 있는 요소들을 참조합니다. 현재 표준은 [container.reqmts]/67 의 포괄적 명시를 통해 이 보장을 제공하며, LWG issue 2321 를 통해 더 직접적인 보장이 검토 중에 있습니다.
C++23까지 공식적으로 요구되지는 않지만, 일부 구현에서는 이미 이전 모드에서 템플릿 매개변수
Allocator
를
비추론 컨텍스트
에 포함시켰습니다.
| Feature-test 매크로 | 값 | 표준 | 기능 |
|---|---|---|---|
__cpp_lib_containers_ranges
|
202202L
|
(C++23) | Ranges-aware 생성 및 삽입; 오버로드 ( 12,13 ) |
예제
#include <iostream> #include <map> #include <utility> struct Point { double x, y; }; struct PointCmp { bool operator()(const Point& lhs, const Point& rhs) const { return lhs.x < rhs.x; // NB. ignores y on purpose } }; template <typename Key, typename Value, typename Cmp> void println(auto rem, const std::multimap<Key, Value, Cmp>& map) { std::cout << rem << "{ "; for (auto n{map.size()}; const auto& p : map) std::cout << '[' << p.first << ":" << p.second << (--n ? "], " : "]"); std::cout << " }\n"; } int main() { std::multimap<int, int> m1 = { {1, 1}, {2, 2}, {3, 3}, {4, 4}, {4, 4}, {3, 3}, {2, 2}, {1, 1} }; println("m1 = ", m1); // Custom comparison std::multimap<Point, double, PointCmp> mag { {{5, 12}, 13}, {{3, 4}, 5}, {{8, 15}, 17}, {{3, -3}, -1} }; for (auto p : mag) std::cout << "The magnitude of (" << p.first.x << ", " << p.first.y << ")" " is " << p.second << '\n'; std::cout << "Construction from a range:\n"; using PS = std::pair<int, std::string>; const auto rg = {PS{3, "Earth"}, {2, "Venus"}, {1, "Mercury"}, {3, "Moon"}}; #if __cpp_lib_containers_ranges std::multimap<int, std::string> m2(std::from_range, rg); // overload (12) #else std::multimap<int, std::string> m2(rg.begin(), rg.end()); // fallback to (4) #endif println("m2 = ", m2); }
출력:
m1 = { [1:1], [1:1], [2:2], [2:2], [3:3], [3:3], [4:4], [4:4] }
The magnitude of (3, 4) is 5
The magnitude of (3, -3) is -1
The magnitude of (5, 12) is 13
The magnitude of (8, 15) is 17
Construction from a range:
m2 = { [1:Mercury], [2:Venus], [3:Earth], [3:Moon] }
결함 보고서
다음 동작 변경 결함 보고서들은 이전에 발표된 C++ 표준에 소급 적용되었습니다.
| DR | 적용 대상 | 게시된 동작 | 올바른 동작 |
|---|---|---|---|
| LWG 2076 | C++11 |
오버로드
(
4
)
가 조건부로 요구함
Key
와
T
가
CopyInsertable
into
*
this
|
요구되지 않음 |
| LWG 2193 | C++11 | 기본 생성자가 explicit였음 | non-explicit로 변경됨 |
참고 항목
|
컨테이너에 값을 할당합니다
(public member function) |