std::flat_multimap<Key,T,Compare,KeyContainer,MappedContainer>::operator=
来自 cppreference.com
flat_multimap& operator=( const flat_multimap& other ); |
(1) | (自 C++23 起) (隐式声明) |
flat_multimap& operator=( flat_multimap&& other ); |
(2) | (自 C++23 起) (隐式声明) |
flat_multimap& operator=( std::initializer_list<value_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_map> #include <initializer_list> #include <print> #include <utility> int main() { std::flat_multimap<int, int> x{{1, 1}, {2, 2}, {3, 3}}, y, z; const auto w = {std::pair<const int, int>{4, 4}, {5, 5}, {6, 6}, {7, 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: 1, 2: 2, 3: 3} y = {} z = {} Copy assignment copies data from x to y: x = {1: 1, 2: 2, 3: 3} y = {1: 1, 2: 2, 3: 3} Move assignment moves data from x to z, modifying both x and z: x = {} z = {1: 1, 2: 2, 3: 3} Assignment of initializer_list w to z: w = {4: 4, 5: 5, 6: 6, 7: 7} z = {4: 4, 5: 5, 6: 6, 7: 7}
[编辑] 另请参阅
构造 flat_multimap (公有成员函数) | |
替换底层容器 (公有成员函数) |