std::experimental::function<R(Args...)>::function
< cpp | experimental | function
function() noexcept;
|
(1) | (库基础 TS) |
function( std::nullptr_t ) noexcept;
|
(2) | (库基础 TS) |
function( const function& other );
|
(3) | (库基础 TS) |
function( function&& other );
|
(4) | (库基础 TS) |
template< class F >
function( F f ); |
(5) | (库基础 TS) |
(6) | ||
template< class Alloc >
function( std::allocator_arg_t, const Alloc& alloc ) noexcept; |
(库基础 TS) | |
function( std::allocator_arg_t,
const allocator_type& alloc ) noexcept; |
(库基础 TS v3) | |
(7) | ||
template< class Alloc >
function( std::allocator_arg_t, const Alloc& alloc, |
(库基础 TS) | |
function( std::allocator_arg_t, const allocator_type& alloc,
std::nullptr_t ) noexcept; |
(库基础 TS v3) | |
(8) | ||
template< class Alloc >
function( std::allocator_arg_t, const Alloc& alloc, |
(库基础 TS) | |
function( std::allocator_arg_t, const allocator_type& alloc,
const function& other ); |
(库基础 TS v3) | |
(9) | ||
(库基础 TS) | ||
function( std::allocator_arg_t, const allocator_type& alloc,
function&& other ); |
(库基础 TS v3) | |
(10) | ||
template< class F, class Alloc >
function( std::allocator_arg_t, const Alloc& alloc, F f ); |
(库基础 TS) | |
function( std::allocator_arg_t, const allocator_type& alloc, F f );
|
(库基础 TS v3) | |
从各种源构造 std::experimental::function
。
1,2) 构造空 function。
3) 复制 other 的目标到 *this 的目标。若 other 为空,则调用后 *this 将亦为空。
4) 移动 other 的目标到 *this 的目标。若 other 为空,则调用后 *this 将亦为空。构造后,*this 存储 other.get_allocator() 的副本。 (库基础 TS v3)
6-10) 同 (1-5),但用 alloc 分配
function
可能使用的任何内部数据结构的内存。这些构造函数将 alloc 当做类型擦除的分配器(见下文)。 (库基础 TS v3 前)
以 (1-5) 构造后,this->get_memory_resource() 将返回构造中std::experimental::pmr::get_default_resource() 返回的相同值。 |
(库基础 TS) (库基础 TS v3 前) |
以 (1-3) 和 (5) 构造后,*this 存储默认构造的 std::pmr::polymorphic_allocator<>。 |
(库基础 TS v3) |
当目标为函数指针或 std::reference_wrapper 时,保证小对象优化,即始终直接存储这些目标于 std::experimental::function 对象内,不发生动态分配。其他大对象可能在动态分配的存储中构造,并由 std::experimental::function 对象通过指针访问。
若构造函数移动或复制了函数对象,包括 std::experimental::function
的实例,则由使用分配器构造用分配器 this->get_memory_resource() (库基础 TS v3 前)this->get_allocator() (库基础 TS v3) 进行移动或复制。
类型擦除的分配器
function
的接收分配器参数 alloc
的构造函数将实参当做类型擦除的分配器。以分配器实参(若指定)确定 function
用来分配内存的 memory_resource 指针,如下:
alloc 的类型 |
memory_resource 指针的值 |
不存在(构造时不指定分配器) | 构造时 std::experimental::pmr::get_default_resource() 的值。 |
std::nullptr_t | 构造时 std::experimental::pmr::get_default_resource() 的值。 |
可转换为 std::experimental::pmr::memory_resource* 的指针类型 |
static_cast<std::experimental::pmr::memory_resource*>(alloc) |
std::experimental::pmr::polymorphic_allocator 的特化 |
alloc.resource() |
任何其他符合分配器要求的类型 | 指向 std::experimental::pmr::resource_adaptor<A>(alloc) 类型对象的指针,其中 A 是 alloc 的类型。指针仅在 function 对象的生存期内保持合法。 |
非以上类型 | 程序非良构 |
参数
other | - | 用于初始化 *this 的函数对象 |
f | - | 用于初始化 *this 的可调用对象 |
alloc | - | 用于内部内存分配的分配器 |
类型要求 | ||
-
F 必须满足可调用 (Callable) 和 可复制构造 (CopyConstructible) 。 |
异常
4) (无)
9) (无)
示例
本节未完成 原因:暂无示例 |