std::flat_set<Key,Compare,KeyContainer>::operator=
来自 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) 复制赋值运算符。用 other 内容的副本替换内容。实际上调用 c = other.c; comp = other.comp;。
2) 移动赋值运算符。使用移动语义用 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 (公共成员函数) | |
替换底层容器 (公共成员函数) |