名稱空間
變體
操作

std::experimental::function<R(Args...)>::operator=

來自 cppreference.com
 
 
實驗性
技術規範
檔案系統庫 (檔案系統 TS)
庫基礎 (庫基礎 TS)
庫基礎 2 (庫基礎 TS v2)
庫基礎 3 (庫基礎 TS v3)
並行性擴充套件 (並行性 TS)
並行性擴充套件 2 (並行性 TS v2)
併發性擴充套件 (併發性 TS)
併發擴充套件 2 (併發 TS v2)
概念 (概念 TS)
範圍 (範圍 TS)
反射 (反射 TS)
數學特殊函式 (特殊函式 TR)
實驗性非 TS
模式匹配
線性代數
std::execution
契約
2D 圖形
 
 
 
function& operator=( const function& other );
(1) (庫基礎 TS)
function& operator=( function&& other );
(2) (庫基礎 TS)
function& operator=( std::nullptr_t ) noexcept;
(3) (庫基礎 TS)
template< class F >
function& operator=( F&& f );
(4) (庫基礎 TS)
(5)
template< class F >
function& operator=( std::reference_wrapper<F> f );
(庫基礎 TS)
template< class F >
function& operator=( std::reference_wrapper<F> f ) noexcept;
(庫基礎 TS v3)

將新“目標”分配給 std::experimental::function。在以下描述中,設 ALLOCATOR_OF(f) 為在 f 構造時指定的分配器,如果未指定分配器,則為 構造時 std::experimental::pmr::get_default_resource() 的值(直到庫基礎 TS v3)預設構造的 std::pmr::polymorphic_allocator<>(庫基礎 TS v3)

1) 賦值 other 的“目標”副本,如同執行 function(std::allocator_arg, ALLOCATOR_OF(*this), other).swap(*this);
2)other 的“目標”移動到 *this,如同執行 function(std::allocator_arg, ALLOCATOR_OF(*this), std::move(other)).swap(*this);other 處於有效狀態,其值未指定。
3) 銷燬 *this 的“目標”。呼叫後 *this 為“空”。賦值後 get_memory_resource() 返回的記憶體資源與賦值前相同,但地址可能改變。
4)*this 的“目標”設定為可呼叫物件 f,如同執行 function(std::allocator_arg, ALLOCATOR_OF(*this),std::forward<F>(f)).swap(*this);。此運算子不參與過載決議,除非 f 對於引數型別 Args... 和返回型別 R可呼叫 (Callable) 的。
5)*this 的“目標”設定為 f 的副本,如同執行 function(std::allocator_arg, ALLOCATOR_OF(*this), f).swap(*this);

目錄

[編輯] 引數

其他 - 另一個 std::experimental::function 物件,用於複製或移動
f - 一個可呼叫物件,用於初始化“目標”
型別要求
-
F 必須滿足 可呼叫 (Callable) 的要求。

[編輯] 返回值

*this

[編輯] 異常

1,2,4) 如果需要為 *this 的目標分配儲存或初始化,則可能丟擲異常。
5) (無)

[編輯] 注意

如果 get_memory_resource() != other.get_memory_resource()(直到庫基礎 TS v3)get_allocator() != other.get_allocator()(庫基礎 TS v3),移動賦值運算子可能需要分配儲存。