std::experimental::function<R(Args...)>::operator=
來自 cppreference.com
< cpp | experimental | function
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)。
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) 的。目錄 |
[編輯] 引數
其他 | - | 另一個 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),移動賦值運算子可能需要分配儲存。