std::function_ref:: function_ref
|
template
<
class
F
>
function_ref ( F * f ) noexcept ; |
(1) | (C++26 起) |
|
template
<
class
F
>
function_ref ( F && f ) noexcept ; |
(2) | (C++26 起) |
|
template
<
auto
f
>
function_ref ( std:: nontype_t < f > ) noexcept ; |
(3) | (C++26 起) |
|
template
<
auto
f,
class
U
>
function_ref ( std:: nontype_t < f > , U && obj ) noexcept ; |
(4) | (C++26 起) |
|
template
<
auto
f,
class
T
>
function_ref ( std:: nontype_t < f > , /*cv*/ T * obj ) noexcept ; |
(5) | (C++26 起) |
|
function_ref
(
const
function_ref
&
other
)
=
default
;
|
(6) | (C++26 起) |
创建一个新的
std::function_ref
。
bound-entity
,并使用函数
thunk
的地址初始化
thunk-ptr
。若
f
为空指针则行为未定义。
- 仅当 std:: is_function_v < F > 与 /*is-invocable-using*/ < F > 均为 true 时,此重载参与重载决议。
bound-entity
,并使用函数
thunk
的地址初始化
thunk-ptr
。
-
令
T
为
std::
remove_reference_t
<
F
>
。此重载仅在以下条件满足时参与重载决议:
-
std::
remove_cvref_t
<
F
>
与
function_ref类型不同, - std:: is_member_pointer_v < T > 为 false ,且
- /*is-invocable-using*/ < /*cv*/ T & > 为 true 。
-
std::
remove_cvref_t
<
F
>
与
bound-entity
,并使用函数
thunk
的地址初始化
thunk-ptr
。
- 令 F 为 decltype ( f ) 。仅当 /*is-invocable-using*/ < F > 为 true 时,此重载参与重载决议。
- 当 std:: is_pointer_v < F > || std:: is_member_pointer_v < F > 为 true 时,若 f ! = nullptr 为 false 则程序非良构。
bound-entity
,并使用函数
thunk
的地址初始化
thunk-ptr
。
-
令
T
为
std::
remove_reference_t
<
U
>
,
F
为
decltype
(
f
)
。此重载仅当满足以下条件时参与重载决议:
- std:: is_rvalue_reference_v < U && > 为 false ,且
- /*is-invocable-using*/ < F, /*cv*/ T & > 为 true 。
- 当 std:: is_pointer_v < F > || std:: is_member_pointer_v < F > 为 true 时,若 f ! = nullptr 为 false ,则程序非良构。
bound-entity
,并使用函数
thunk
的地址初始化
thunk-ptr
。当
std::
is_member_pointer_v
<
F
>
为
true
时,若
obj
为空指针则行为未定义。
- 令 F 为 decltype ( f ) 。仅当 /*is-invocable-using*/ < F, /*cv*/ T * > 为 true 时,此重载参与重载决议。
- 当 std:: is_pointer_v < F > || std:: is_member_pointer_v < F > 为 true 时,若 f ! = nullptr 为 false 则程序非良构。
bound-entity
与
thunk-ptr
。
函数
thunk
的地址用于初始化
thunk-ptr
,使得对
thunk
(
bound-entity
,
call-args
...
)
的调用与以下表达式
表达式等价
:
| 重载版本 | 表达式等价形式 |
|---|---|
| ( 1,3 ) |
std::
invoke_r
<
R
>
(
f,
call-args
...
)
|
| ( 2 ) |
std::
invoke_r
<
R
>
(
static_cast
<
cv
T
&
>
(
f
)
,
call-args
...
)
|
| ( 4 ) |
std::
invoke_r
<
R
>
(
f,
static_cast
<
cv
T
&
>
(
obj
)
,
call-args
...
)
|
| ( 5 ) |
std::
invoke_r
<
R
>
(
f, obj,
call-args
...
)
|
/*is-invocable-using*/ < T... > 当且仅当以下条件成立时为 true :
- 当 noex 为 true 时, std:: is_nothrow_invocable_r_v < R, T..., Args... > 为 true ,或者
- std:: is_invocable_r_v < R, T..., Args... > 为 true
参数
| other | - |
待复制的另一个
function_ref
|
| f | - | 要包装的函数或 Callable 对象 |
| obj | - | 要绑定的对象或指针 |
示例
|
本节内容不完整
原因:缺少示例 |
另请参阅
构造新的
std::move_only_function
对象
(
std::move_only_function
的公开成员函数)
|