std::forward_list<T,Allocator>:: operator=
|
forward_list
&
operator
=
(
const
forward_list
&
other
)
;
|
(1) |
(C++11부터)
(C++26부터 constexpr) |
| (2) | ||
|
forward_list
&
operator
=
(
forward_list
&&
other
)
;
|
(C++11부터)
(C++17까지) |
|
|
forward_list
&
operator
=
(
forward_list
&&
other
)
noexcept ( /* 아래 참조 */ ) ; |
(C++17부터)
(C++26부터 constexpr) |
|
|
forward_list
&
operator
=
(
std::
initializer_list
<
value_type
>
ilist
)
;
|
(3) |
(C++11부터)
(C++26부터 constexpr) |
컨테이너의 내용을 대체합니다.
traits
를
std::
allocator_traits
<
allocator_type
>
로 정의합니다:
목차매개변수
반환값* this 복잡도
1)
*
this
와
other
의 크기에 선형적으로 비례합니다.
2)
할당자(allocator)가 동일하지 않고 전파(propagate)되지 않는 경우를 제외하면
*
this
의 크기에 대해 선형적(linear)이며, 이 경우
*
this
와
other
의 크기에 대해 선형적입니다.
3)
*
this
와
ilist
의 크기에 선형적으로 비례합니다.
예외
참고컨테이너 이동 할당(오버로드 (2)) 후에, 호환되지 않는 할당자에 의해 요소별 이동 할당이 강제되지 않는 한, 원래 예제다음 코드는 operator = 를 사용하여 하나의 std::forward_list 를 다른 것으로 할당합니다:
이 코드 실행
#include <initializer_list> #include <iostream> #include <iterator> #include <forward_list> void print(const auto comment, const auto& container) { auto size = std::ranges::distance(container); std::cout << comment << "{ "; for (const auto& element : container) std::cout << element << (-- size ? ", " : " "); std::cout << "}\n"; } int main() { std::forward_list<int> x{1, 2, 3}, y, z; const auto w = {4, 5, 6, 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, 2, 3 }
y = { }
z = { }
Copy assignment copies data from x to y:
x = { 1, 2, 3 }
y = { 1, 2, 3 }
Move assignment moves data from x to z, modifying both x and z:
x = { }
z = { 1, 2, 3 }
Assignment of initializer_list w to z:
w = { 4, 5, 6, 7 }
z = { 4, 5, 6, 7 }
참고 항목
|