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