std::copyable_function::copyable_function

来自cppreference.com
 
 
 
函数对象
函数调用
(C++17)(C++23)
恒等函数对象
(C++20)
旧式绑定器与适配器
(C++17 前*)
(C++17 前*)
(C++17 前*)
(C++17 前*)
(C++17 前*)(C++17 前*)(C++17 前*)(C++17 前*)
(C++20 前*)
(C++20 前*)
(C++17 前*)(C++17 前*)
(C++17 前*)(C++17 前*)

(C++17 前*)
(C++17 前*)(C++17 前*)(C++17 前*)(C++17 前*)
(C++20 前*)
(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)VTstd::decay_t<F>。如果 f 是空函数指针,空成员指针值,或者空的 std::copyable_function(可为其他任意特化),那么构造空的 std::copyable_function。否则,构造 std::copyable_function,其目标类型为 VT 并以 std::forward<F>(f) 进行直接非列表初始化。
6)VTstd::decay_t<T>。构造 std::copyable_function,其目标类型为 VT 并以 std::forward<CArgs>(args)... 进行直接非列表初始化。
7)VTstd::decay_t<T>。构造 std::copyable_function,其目标类型为 VT 并以 il, std::forward<CArgs>(args)... 进行直接非列表初始化。

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

常量 /*is-callable-from*/<VT> 依赖于 std::copyable_function 的模板形参中的 cvrefnoex 如下:

cv ref noexcept(noex)/*is-callable-from*/<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-要包装的函数或可调用 (Callable) 对象
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 的公开成员函数)