std::flat_set<Key,Compare,KeyContainer>:: operator=
From cppreference.net
|
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)
复制赋值运算符。将内容替换为
other
内容的副本。实际调用
c
=
other.
c
;
comp
=
other.
comp
;
。
2)
移动赋值运算符。使用移动语义将内容替换为
other
的内容。实际调用
c
=
std
::
move
(
other.
c
)
;
comp
=
std
::
move
(
other.
comp
)
;
。
3)
将内容替换为由初始化列表
ilist
所标识的内容。
目录 |
参数
| other | - | 用作源的另一容器适配器 |
| 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("初始状态:"); std::println("x = {}", x); std::println("y = {}", y); std::println("z = {}", z); y = x; // 重载 (1) std::println("复制赋值将数据从 x 复制到 y:"); std::println("x = {}", x); std::println("y = {}", y); z = std::move(x); // 重载 (2) std::println("移动赋值将数据从 x 移动到 z,同时修改 x 和 z:"); std::println("x = {}", x); std::println("z = {}", z); z = w; // 重载 (3) std::println("将初始化列表 w 赋值给 z:"); std::println("w = {}", w); std::println("z = {}", z); }
输出:
初始状态:
x = {1, 2, 3}
y = {}
z = {}
复制赋值将数据从 x 复制到 y:
x = {1, 2, 3}
y = {1, 2, 3}
移动赋值将数据从 x 移动到 z,同时修改 x 和 z:
x = {}
z = {1, 2, 3}
将初始化列表 w 赋值给 z:
w = {4, 5, 6, 7}
z = {4, 5, 6, 7}
另请参阅
构造
flat_set
(公开成员函数) |
|
|
替换底层容器
(公开成员函数) |