std::multimap<Key,T,Compare,Allocator>:: operator=
|
multimap
&
operator
=
(
const
multimap
&
other
)
;
|
(1) | (constexpr since C++26) |
| (2) | ||
|
multimap
&
operator
=
(
multimap
&&
other
)
;
|
(since C++11)
(until C++17) |
|
|
multimap
&
operator
=
(
multimap
&&
other
)
noexcept ( /* see below */ ) ; |
(since C++17)
(constexpr since C++26) |
|
|
multimap
&
operator
=
(
std::
initializer_list
<
value_type
>
ilist
)
;
|
(3) |
(since C++11)
(constexpr since C++26) |
컨테이너의 내용을 대체합니다.
traits
를
std::
allocator_traits
<
allocator_type
>
로 정의합니다:
|
만약 traits :: propagate_on_container_copy_assignment :: value 가 true 라면, * this 의 할당자가 other 의 할당자 복사본으로 대체됩니다. 만약 할당 후 * this 의 할당자가 이전 값과 비교하여 같지 않다면, 이전 할당자를 사용하여 메모리를 해제한 후 새로운 할당자를 사용하여 메모리를 할당하고 요소들을 복사합니다. 그렇지 않으면, * this 가 소유한 메모리는 가능한 경우 재사용될 수 있습니다. 어떤 경우든, 원래 * this 에 속했던 요소들은 파괴되거나 요소별 복사 할당으로 대체될 수 있습니다. |
(since C++11) |
목차매개변수
반환값* this 복잡도
1)
*
this
와
other
의 크기에 선형적으로 비례합니다.
2)
할당자(allocator)가 서로 같지 않고 전파(propagate)되지 않는 경우를 제외하면
*
this
의 크기에 대해 선형적(linear)이며, 이 경우에는
*
this
와
other
의 크기에 대해 선형적입니다.
3)
O(N·log(N))
일반적으로, 여기서
N
은
size
(
)
+
ilist.
size
(
)
입니다.
ilist
가
value_comp()
에 대해 정렬된 경우 선형 시간입니다.
예외
참고컨테이너 이동 할당(오버로드 (2)) 후, 호환되지 않는 할당자로 인해 요소별 이동 할당이 강제되지 않는 한, 원래 예제다음 코드는 operator = 를 사용하여 하나의 std::multimap 을 다른 multimap에 할당합니다:
이 코드 실행
#include <initializer_list> #include <iostream> #include <iterator> #include <map> #include <utility> void print(const auto comment, const auto& container) { auto size = std::size(container); std::cout << comment << "{ "; for (const auto& [key, value] : container) std::cout << '{' << key << ',' << value << (--size ? "}, " : "} "); std::cout << "}\n"; } int main() { std::multimap<int, int> x{{1,1}, {2,2}, {3,3}}, y, z; const auto w = {std::pair<const int, int>{4,4}, {5,5}, {6,6}, {7,7}}; std::cout << "Initially:\n"; print("x = ", x); print("y = ", y); print("z = ", z); std::cout << "Copy assignment copies data from x to y:\n"; y = x; print("x = ", x); print("y = ", y); std::cout << "Move assignment moves data from x to z, modifying both x and z:\n"; z = std::move(x); print("x = ", x); print("z = ", z); std::cout << "Assignment of initializer_list w to z:\n"; z = w; print("w = ", w); print("z = ", z); } 출력: Initially:
x = { {1,1}, {2,2}, {3,3} }
y = { }
z = { }
Copy assignment copies data from x to y:
x = { {1,1}, {2,2}, {3,3} }
y = { {1,1}, {2,2}, {3,3} }
Move assignment moves data from x to z, modifying both x and z:
x = { }
z = { {1,1}, {2,2}, {3,3} }
Assignment of initializer_list w to z:
w = { {4,4}, {5,5}, {6,6}, {7,7} }
z = { {4,4}, {5,5}, {6,6}, {7,7} }
참고 항목
|