std:: reference_constructs_from_temporary
| Type traits | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Compile-time rational arithmetic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Compile-time integer sequences | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
(C++14)
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
定义于头文件
<type_traits>
|
||
|
template
<
class
T,
class
U
>
struct reference_constructs_from_temporary ; |
(C++23 起) | |
若
U
是标量类型或
cv
void
,则令
V
为
std::
remove_cv_t
<
U
>
,否则为
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_constructs_from_temporary
或
std::reference_constructs_from_temporary_v
添加特化,则行为是未定义的。
目录 |
辅助变量模板
|
template
<
class
T,
class
U
>
inline
constexpr
bool
reference_constructs_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_constructs_from_temporary
可用于拒绝某些总是产生悬垂引用的情况。
如果编译器已实现 CWG1696 ,也可以使用成员初始化列表来拒绝将临时对象绑定到引用。
示例
#include <type_traits> static_assert(std::reference_constructs_from_temporary_v<int&&, int> == true); static_assert(std::reference_constructs_from_temporary_v<const int&, int> == true); static_assert(std::reference_constructs_from_temporary_v<int&&, int&&> == false); static_assert(std::reference_constructs_from_temporary_v<const int&, int&&> == false); static_assert(std::reference_constructs_from_temporary_v<int&&, long&&> == true); static_assert(std::reference_constructs_from_temporary_v<int&&, long> == true); int main() {}
参见
|
(C++11)
(C++11)
(C++11)
|
检查类型是否具有特定参数的构造函数
(类模板) |
构造新的
tuple
(
std::tuple<Types...>
的公开成员函数)
|
|
构造新的
pair
(
std::pair<T1,T2>
的公开成员函数)
|
|
|
(C++17)
|
使用参数元组构造对象
(函数模板) |