c++ std::is_nothrow_move_constructible

std::is_nothrow_move_constructible是一个C++模板,用于判断类型是否具备无异常的移动构造函数。如果类型T的移动构造函数不会抛出异常,则返回true,否则返回false。这个特性在编写高效且安全的代码时非常有用。示例代码展示了如何使用该模板检查不同类型的移动构造函数行为。
摘要由CSDN通过智能技术生成

std::is_nothrow_move_constructible是c++stl标准库中定义的一个模板,该模板用于检测给定的类型T是否是可移动构造的,并且移动构造是noexcept的;如果T是可移动构造且移动构造不会抛出异常,则返回true,否则返回false;
cplusplus链接:http://www.cplusplus.com/reference/type_traits/is_nothrow_move_constructible/

头文件:
#include<type_traits>
模板类别:
template <class T>
struct is_nothrow_move_constructible;
使用方法:
std::is_nothrow_move_constructible<T>::value
参数:

模板std::is_nothrow_move_constructible接受单个参数T(Trait类),以检查T是否为可移动构造类型。

返回值:

true: 如果类型T是可移动构造类型;
false: 如果类型T不是可移动构造类型;

示例代码:

摘自:http://www.cplusplus.com/reference/type_traits/is_nothrow_move_constructible/

// is_nothrow_move_constructible example
#include <iostream>
#include <type_traits>

struct A { };
struct B { B(B&&){} };
struct C { C(C&&) noexcept {} };

int main() {
  std::cout << std::boolalpha;
  std::cout << "is_nothrow_move_constructible:" << std::endl;
  std::cout << "int: " << std::is_nothrow_move_constructible<int>::value << std::endl;
  std::cout << "A: " << std::is_nothrow_move_constructible<A>::value << std::endl;
  std::cout << "B: " << std::is_nothrow_move_constructible<B>::value << std::endl;
  std::cout << "C: " << std::is_nothrow_move_constructible<C>::value << std::endl;
  return 0;
}
运行结果:
is_nothrow_move_constructible:
int: true
A: true
B: false
C: true
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值