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
>
とします:
目次 |
パラメータ
| other | - | データソースとして使用する別のコンテナ |
| ilist | - | データソースとして使用する初期化子リスト |
戻り値
* this
計算量
例外
|
2)
noexcept
仕様:
noexcept
(
std::
allocator_traits
<
Allocator
>
::
is_always_equal
::
value
)
|
(C++17以降) |
注記
コンテナのムーブ代入(オーバーロード ( 2 ) 後)、要素ごとのムーブ代入が互換性のないアロケータによって強制されない限り、 other への参照、ポインタ、およびイテレータ(終端イテレータを除く)は有効なままですが、現在は * this 内の要素を参照します。現在の標準は [container.reqmts]/67 での包括的な記述によってこの保証を行っており、より直接的な保証が LWG issue 2321 を通じて検討中です。
例
以下のコードは 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 }
関連項目
forward_list
を構築する
(public member function) |
|
|
コンテナに値を割り当てる
(public member function) |