std:: reference_converts_from_temporary
|
定义于头文件
<type_traits>
|
||
|
template
<
class
T,
class
U
>
struct reference_converts_from_temporary ; |
(C++23 起) | |
令
V
为
std::
remove_cv_t
<
U
>
(若
U
为标量类型或
cv
void
),否则为
U
。若
T
是引用类型,且给定假设表达式
e
使得
decltype
(
e
)
为
V
,变量定义
T ref
=
e
;
是良构的且
将临时对象绑定
至
ref
,则提供等于
true
的成员常量
value
。否则
value
为
false
。
如果
T
是 const 限定(非 volatile 限定)对象类型的左值引用类型或右值引用类型,则
std::
remove_reference_t
<
T
>
和
std::
remove_reference_t
<
U
>
都应为
完整类型
、
cv
void
或
未知边界数组
;否则行为未定义。
如果上述模板的实例化直接或间接依赖于不完整类型,且该实例化在该类型被假设完成时可能产生不同结果,则行为是未定义的。
如果程序为
std::reference_converts_from_temporary
或
std::reference_converts_from_temporary_v
添加特化,则行为未定义。
目录 |
辅助变量模板
|
template
<
class
T,
class
U
>
inline
constexpr
bool
reference_converts_from_temporary_v
=
|
(C++23 起) | |
继承自 std:: integral_constant
成员常量
|
value
[static]
|
若
T
是引用类型,且
U
值在复制初始化中可绑定到
T
,且临时对象将绑定到该引用,则为
true
;否则为
false
(公开静态成员常量) |
成员函数
|
operator bool
|
转换对象为
bool
类型,返回
value
(公开成员函数) |
|
operator()
(C++14)
|
返回
value
(公开成员函数) |
成员类型
| 类型 | 定义 |
value_type
|
bool |
type
|
std:: integral_constant < bool , value > |
注释
std::reference_converts_from_temporary
可用于拒绝某些总是产生悬垂引用的情况。
示例
#include <type_traits> int main() {} static_assert( std::reference_converts_from_temporary_v<int&&, int> == true && std::reference_converts_from_temporary_v<const int&, int> == true && std::reference_converts_from_temporary_v<int&&, int&&> == false && std::reference_converts_from_temporary_v<const int&, int&&> == false && std::reference_converts_from_temporary_v<int&&, long&&> == true && std::reference_converts_from_temporary_v<int&&, long> == true);
参见
|
(C++11)
(C++20)
|
检查一个类型是否能转换为另一个类型
(类模板) |
|
(C++17)
(C++23)
|
使用给定参数调用任意
Callable
对象
并可指定返回类型
(C++23 起)
(函数模板) |
|
(C++11)
|
将一个或多个参数绑定到函数对象
(函数模板) |
|
(C++17)
|
使用一个或多个
variant
持有的参数调用提供的函数对象
(函数模板) |
构造新的
std::function
实例
(
std::function<R(Args...)>
的公开成员函数)
|
|
构造新的
std::move_only_function
对象
(
std::move_only_function
的公开成员函数)
|
|
|
构造任务对象
(
std::packaged_task<R(Args...)>
的公开成员函数)
|