名稱空間
變體
操作

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 標識的內容替換內容。

目錄

[編輯] 引數

其他 - 另一個用作源的容器介面卡
ilist - 用作源的初始化器列表

[編輯] 返回值

*this

[編輯] 複雜度

1,2) 等同於底層容器的 operator= 的複雜度。
3)*thisilist 的大小呈線性關係。

[編輯] 示例

#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
(public member function) [edit]
替換底層容器
(public member function) [edit]