名稱空間
變體
操作

std::flat_multiset<Key,Compare,KeyContainer>::operator=

來自 cppreference.com
 
 
 
 
flat_multiset& operator=( const flat_multiset& other );
(1) (C++23 起)
(隱式宣告)
flat_multiset& operator=( flat_multiset&& other );
(2) (C++23 起)
(隱式宣告)
flat_multiset& 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)*thisilist 的大小呈線性關係。

[編輯] 示例

#include <flat_set>
#include <initializer_list>
#include <print>
 
int main()
{
    std::flat_multiset<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_multiset
(公共成員函式) [編輯]
替換底層容器
(公共成員函式) [編輯]