std::flat_set<Key,Compare,KeyContainer>::operator=
From cppreference.com
| flat_set& operator=( const flat_set& other ); |
(1) | (C++23から) (暗黙的に宣言) |
| flat_set& operator=( flat_set&& other ); |
(2) | (C++23から) (暗黙的に宣言) |
| flat_set& operator=( std::initializer_list<key_type> ilist ); |
(3) | (C++23から) |
コンテナアダプタの内容を指定された引数の内容で置き換えます。
1) コピー代入演算子。contentsを`other`のcontentsのコピーで置き換えます。実質的には `c = other.c; comp = other.comp;` を呼び出します。
2) ムーブ代入演算子。ムーブセマンティクスを使用して、contentsを`other`のものと置き換えます。実質的には `c = std::move(other.c); comp = std::move(other.comp);` を呼び出します。
3) コンテナの内容を初期化リスト ilist で指定された内容で置き換えます。
目次 |
[編集] パラメータ
| その他 | - | ソースとして使用される別のコンテナアダプタ |
| ilist | - | ソースとして使用される初期化リスト |
[編集] 戻り値
*this
[編集] 計算量
1,2) 基底となるコンテナの
operator= の計算量に相当します。3) *this および ilist のサイズに対する線形。
[編集] 例
このコードを実行
#include <flat_set> #include <initializer_list> #include <print> int main() { std::flat_set<int> x{1, 2, 3}, y, z; const auto w = {4, 5, 6, 7}; std::println("Initially:"); std::println("x = {}", x); std::println("y = {}", y); std::println("z = {}", z); y = x; // overload (1) std::println("Copy assignment copies data from x to y:"); std::println("x = {}", x); std::println("y = {}", y); z = std::move(x); // overload (2) std::println("Move assignment moves data from x to z, modifying both x and z:"); std::println("x = {}", x); std::println("z = {}", z); z = w; // overload (3) std::println("Assignment of initializer_list w to z:"); std::println("w = {}", w); std::println("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}[編集] 関連項目
flat_set を構築します(公開メンバ関数) | |
| 基になるコンテナを置き換える (public member function) |