std:: is_swappable_with, std:: is_swappable, std:: is_nothrow_swappable_with, std:: is_nothrow_swappable
|
定义于头文件
<type_traits>
|
||
|
template
<
class
T,
class
U
>
struct is_swappable_with ; |
(1) | (C++17 起) |
|
template
<
class
T
>
struct is_swappable ; |
(2) | (C++17 起) |
|
template
<
class
T,
class
U
>
struct is_nothrow_swappable_with ; |
(3) | (C++17 起) |
|
template
<
class
T
>
struct is_nothrow_swappable ; |
(4) | (C++17 起) |
value
。否则
value
为
false
。
| 类型特性 |
成员常量
value
的值
|
|
|---|---|---|
T
是可引用类型
|
T
不是可引用类型
|
|
| (2) | std :: is_swappable_with < T & , T & > :: value | false |
| (4) | std :: is_nothrow_swappable_with < T & , T & > :: value | |
如果
T
或
U
不是完整类型、(可能带有 cv 限定符的)
void
,或未知边界数组,则行为未定义。
如果上述模板的实例化直接或间接依赖于不完整类型,且该实例化在该类型被假设完成时可能产生不同结果,则行为是未定义的。
如果程序对本页面描述的任何模板添加特化,则行为未定义。
目录 |
辅助变量模板
|
template
<
class
T,
class
U
>
inline constexpr bool is_swappable_with_v = is_swappable_with < T, U > :: value ; |
(自 C++17 起) | |
|
template
<
class
T
>
inline constexpr bool is_swappable_v = is_swappable < T > :: value ; |
(自 C++17 起) | |
|
template
<
class
T,
class
U
>
inline
constexpr
bool
is_nothrow_swappable_with_v
=
|
(自 C++17 起) | |
|
template
<
class
T
>
inline
constexpr
bool
is_nothrow_swappable_v
=
|
(自 C++17 起) | |
继承自 std:: integral_constant
成员常量
|
value
[static]
|
若
T
可与
U
交换则为
true
,否则为
false
(公开静态成员常量) |
成员函数
|
operator bool
|
转换对象为
bool
类型,返回
value
(公开成员函数) |
|
operator()
(C++14)
|
返回
value
(公开成员函数) |
成员类型
| 类型 | 定义 |
value_type
|
bool |
type
|
std:: integral_constant < bool , value > |
注释
此特性不会检查交换表达式直接上下文之外的任何内容:如果对
T
或
U
的使用会触发模板特化、隐式定义的特殊成员函数生成等操作,且这些操作存在错误,那么即使
std
::
is_swappable_with
<
T, U
>
::
value
能够编译并通过计算得到
true
,实际的交换操作可能仍无法编译通过。
示例
|
本节内容不完整
原因:缺少示例 |
参见
|
交换两个对象的值
(函数模板) |
|
|
(C++11)
(C++11)
(C++11)
|
检查类型是否具有移动赋值运算符
(类模板) |
|
(C++20)
|
指定类型可交换或两个类型可相互交换
(概念) |