首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::function::function

function();

(1)

(since C++11)

function( std::nullptr_t );

(2)

(since C++11)

function( const function& other );

(3)

(since C++11)

function( function&& other );

(4)

(since C++11)

template< class F > function( F f );

(5)

(since C++11)

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

(6)

(since C++11) (until C++17)

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

(7)

(since C++11) (until C++17)

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

(8)

(since C++11) (until C++17)

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

(9)

(since C++11) (until C++17)

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

(10)

(since C++11) (until C++17)

构造一个std::function来自不同的来源。

1-2%29创建一个空空功能。

3-4%29拷贝%283%29或移动%284%29目标other目标*this.如果other空空,,,*this将是空空也是在电话之后。%284%29,other在调用后处于有效但未指定的状态。

5%29初始化目标带着一份f.如果f是指向函数的空指针或指向成员的空指针,*this将是空空打完电话后。此构造函数不参与重载解析,除非f是Callable用于参数类型Args...返回类型R.%28自C++14%29

6-10%29与%281-5%29相同,但alloc对象的任何内部数据结构分配内存。function可能会用。

目标是函数指针或std::reference_wrapper,就可以保证小对象优化,也就是说,这些目标总是直接存储在std::function对象时,不进行动态分配。其他大型对象可以在动态分配的存储中构造,并由std::function通过指针初始化。

参数

other

-

the function object used to initialize *this

f

-

a callable used to initialize *this

alloc

-

an Allocator used for internal memory allocation

类型要求

-F必须符合可调用和可复制的要求。

-分配器必须符合分配器的要求。

例外

1-2%29

noexcept规格:

noexcept

3,4,8,9%29不抛other%27目标是函数指针或std::reference_wrapper,否则可能会抛出std::bad_alloc或用于复制或移动存储的可调用对象的构造函数引发的任何异常。

5,10%29不抛f是函数指针或std::reference_wrapper,否则可能会抛出std::bad_alloc或存储的可调用对象的复制构造函数引发的任何异常。

6-7%29

noexcept规格:

noexcept

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com