C++ 函式庫 - 建構函式



描述

它從各種來源構造一個 std::function。

宣告

以下是 std::function 的宣告。

C++11

以下是建立空函式的方法。

function();
function( std::nullptr_t );

異常

noexcept:noexcept 說明。

複製和移動

以下函式將其他物件的 target 複製或移動到 *this 的 target。如果 other 為空,則呼叫後 *this 也將為空。

function( const function& other );
function( function&& other );

異常

noexcept:noexcept 說明。

初始化目標

以下函式使用 f 的副本初始化目標。如果 f 是指向函式的空指標或指向成員的空指標,則呼叫後 *this 將為空。除非 f 可對引數型別 Args 和返回型別 R 呼叫,否則此建構函式不參與過載解析。

template< class F > 
function( F f );

異常

noexcept:noexcept 說明。

分配記憶體

以下函式與上述相同,只是使用 alloc 為函式可能使用的任何內部資料結構分配記憶體。

template< class Alloc > 
function( std::allocator_arg_t, const Alloc& alloc );

template< class Alloc > 
function( std::allocator_arg_t, const Alloc& alloc, 
          std::nullptr_t );

template< class Alloc >
function( std::allocator_arg_t, const Alloc& alloc, 
          const function& other );
		  
template< class Alloc > 
function( std::allocator_arg_t, const Alloc& alloc, 
          function&& other );
		  
template< class F, class Alloc > 
function( std::allocator_arg_t, const Alloc& alloc, F f );

異常

noexcept:noexcept 說明。

引數

  • other − 用於初始化 *this 的函式物件。

  • f − 用於初始化 *this 的可呼叫物件。

  • alloc − 用於內部記憶體分配。

functional.htm
廣告