Namespaces
Variants

std::copyable_function:: copyable_function

From cppreference.net
Utilities library
Function objects
Function invocation
(C++17) (C++23)
Identity function object
(C++20)
Old binders and adaptors
( until C++17* )
( until C++17* )
( until C++17* )
( until C++17* )
( until C++17* ) ( until C++17* ) ( until C++17* ) ( until C++17* )
( until C++20* )
( until C++20* )
( until C++17* ) ( until C++17* )
( until C++17* ) ( until C++17* )

( until C++17* )
( until C++17* ) ( until C++17* ) ( until C++17* ) ( until C++17* )
( until C++20* )
( until C++20* )
copyable_function ( ) noexcept ;
(1) (自 C++26 起)
copyable_function ( std:: nullptr_t ) noexcept ;
(2) (自 C++26 起)
copyable_function ( const copyable_function & other ) ;
(3) (自 C++26 起)
copyable_function ( copyable_function && other ) noexcept ;
(4) (自 C++26 起)
template < class F >
copyable_function ( F && f ) ;
(5) (自 C++26 起)
template < class T, class ... CArgs >
explicit copyable_function ( std:: in_place_type_t < T > , CArgs && ... args ) ;
(6) (自 C++26 起)
template < class T, class U, class ... CArgs >

explicit copyable_function ( std:: in_place_type_t < T > ,

std:: initializer_list < U > il, CArgs && ... args ) ;
(7) (自 C++26 起)

创建一个新的 std::copyable_function

1,2) 默认构造函数和接受 nullptr 的构造函数会构造一个空的 std::copyable_function
3) 拷贝构造函数构造一个 std::copyable_function ,其目标对象是 other 目标对象的副本。若 other 为空,则构造一个空的 std::copyable_function
4) 移动构造函数构造一个 std::copyable_function ,其目标对象来自 other 。移动构造后, other 处于有效但未指定的状态。
5) VT std:: decay_t < F > 。若 f 是空函数指针、空成员指针值或空的 std::copyable_function (可为任意其他特化),则构造一个空的 std::copyable_function 。否则,构造一个目标类型为 VT 且通过 std:: forward < F > ( f ) 直接非列表初始化的 std::copyable_function
6) VT std:: decay_t < T > 。构造一个目标对象类型为 VT std::copyable_function ,该目标对象通过 std:: forward < CArgs > ( args ) ... 进行直接非列表初始化。
7) VT std:: decay_t < T > 。构造一个目标对象类型为 VT std::copyable_function ,该目标对象通过 il, std:: forward < CArgs > ( args ) ... 进行直接非列表初始化。

对于构造函数 (5-7) ,除非 VT 同时满足 Destructible CopyConstructible 要求,否则行为未定义。

常量 /*is-callable-from*/ < VT > 依赖于 std::copyable_function 模板参数中的 cv ref noex ,具体如下:

cv ref noexcept ( noex ) /*可从以下调用*/ < VT >
noexcept ( false ) std:: is_invocable_r_v < R, VT, Args... > &&

std:: is_invocable_r_v < R, VT & , Args... >

noexcept ( true ) std:: is_nothrow_invocable_r_v < R, VT, Args... > &&

std:: is_nothrow_invocable_r_v < R, VT & , Args... >

const noexcept ( false ) std:: is_invocable_r_v < R, const VT, Args... > &&

std:: is_invocable_r_v < R, const VT & , Args... >

const noexcept ( true ) std:: is_nothrow_invocable_r_v < R, const VT, Args... > &&

std:: is_nothrow_invocable_r_v < R, const VT & , Args... >

& noexcept ( false ) std:: is_invocable_r_v < R, VT & , Args... >
& noexcept ( true ) std:: is_nothrow_invocable_r_v < R, VT & , Args... >
const & noexcept ( false ) std:: is_invocable_r_v < R, const VT & , Args... >
const & noexcept ( true ) std:: is_nothrow_invocable_r_v < R, const VT & , Args... >
&& noexcept ( false ) std:: is_invocable_r_v < R, VT, Args... >
&& noexcept ( true ) std:: is_nothrow_invocable_r_v < R, VT, Args... >
const && noexcept ( false ) std:: is_invocable_r_v < R, const VT, Args... >
const && noexcept ( true ) std:: is_nothrow_invocable_r_v < R, const VT, Args... >

目录

参数

other - 用于复制或移动来源的另一个 std::copyable_function
f - 要包装的函数或 可调用对象
args - 用于构造目标对象的参数
il - 用于构造目标对象的 std::initializer_list

异常

3) 分配失败时可能抛出 std::bad_alloc ,或传播目标对象初始化时抛出的异常。
5-7) 在分配失败时可能抛出 std::bad_alloc ,或传播目标初始化抛出的异常。若 VT 为函数指针类型或 std::reference_wrapper 的特化,则不抛出异常。

示例

参见

构造新的 std::function 实例
( std::function<R(Args...)> 的公开成员函数)
构造新的 std::move_only_function 对象
( std::move_only_function 的公开成员函数)