std::unordered_map<Key,T,Hash,KeyEqual,Allocator>:: operator=
|
unordered_map
&
operator
=
(
const
unordered_map
&
other
)
;
|
(1) |
(C++11부터)
(C++26부터 constexpr) |
| (2) | ||
|
unordered_map
&
operator
=
(
unordered_map
&&
other
)
;
|
(C++11부터)
(C++17까지) |
|
|
unordered_map
&
operator
=
(
unordered_map
&&
other
)
noexcept ( /* 아래 참조 */ ) ; |
(C++17부터)
(C++26부터 constexpr) |
|
|
unordered_map
&
operator
=
(
std::
initializer_list
<
value_type
>
ilist
)
;
|
(3) |
(C++11부터)
(C++26부터 constexpr) |
컨테이너의 내용을 대체합니다.
traits
를
std::
allocator_traits
<
allocator_type
>
로 정의합니다:
목차 |
매개변수
| other | - | 데이터 소스로 사용할 다른 컨테이너 |
| ilist | - | 데이터 소스로 사용할 초기화 리스트 |
반환값
* this
복잡도
예외
|
2)
noexcept
명세:
noexcept
(
std::
allocator_traits
<
Allocator
>
::
is_always_equal
::
value
&&
std::
is_nothrow_move_assignable
<
Hash
>
::
value
|
(C++17부터) |
참고 사항
컨테이너 이동 대입 후 (오버로드 ( 2 ) ), 호환되지 않는 할당자에 의한 요소별 이동 대입이 강제되지 않는 한, other 에 대한 참조, 포인터, 반복자(끝 반복자 제외)는 유효하게 남아 있지만, 이제 * this 에 있는 요소를 참조합니다. 현재 표준은 [container.reqmts]/67 의 포괄적 명시를 통해 이 보장을 제공하며, LWG issue 2321 를 통해 더 직접적인 보장이 검토 중입니다.
예제
다음 코드는 operator = 를 사용하여 하나의 std::unordered_map 을 다른 하나에 할당합니다:
#include <initializer_list> #include <iostream> #include <iterator> #include <unordered_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::unordered_map<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 = { {3,3}, {2,2}, {1,1} }
y = { }
z = { }
Copy assignment copies data from x to y:
x = { {3,3}, {2,2}, {1,1} }
y = { {3,3}, {2,2}, {1,1} }
Move assignment moves data from x to z, modifying both x and z:
x = { }
z = { {3,3}, {2,2}, {1,1} }
Assignment of initializer_list w to z:
w = { {4,4}, {5,5}, {6,6}, {7,7} }
z = { {7,7}, {6,6}, {5,5}, {4,4} }
참고 항목
unordered_map
을 생성합니다
(public member function) |