<type_traits>头文件中提供了C++ STL的std::is_nothrow_move_constructible模板。 C++ STL的std::is_nothrow_move_constructible模板用于检查给定的类型T T是否为可移动构造,并且众所周知它不会引发任何异常。如果T是可移动构造类型,则返回布尔值true,否则返回false。
头文件:
#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不是可移动构造类型。
下面是说明C /C++中的std::is_nothrow_default_constructible模板的程序:
程序:
// C++ program to illustrate
// std::is_nothrow_move_constructible
#include <bits/stdc++.h>
#include <type_traits>
using namespace std;
// Declare structures
struct B {
};
struct A {
A& operator=(A&) = delete;
};
struct C {
C(C&&) {}
};
struct D {
D(D&&) = delete;
};
// Driver Code
int main()
{
cout << boolalpha;
// Check if int is no throw move
// constructible or not
cout << "int:"
<< is_nothrow_move_constructible<int>::value
<< endl;
// Check if char is no throw move
// constructible or not
cout << "char:"
<< is_nothrow_move_constructible<char>::value
<< endl;
// Check if floar is no throw move
// constructible or not
cout << "float:"
<< is_nothrow_move_constructible<float>::value
<< endl;
// Check if struct A is no throw
// move constructible or not
cout << "struct A is nothrow move constructible? "
<< is_nothrow_move_constructible<A>::value
<< endl;
// Check if struct B is no throw
// move constructible or not
cout << "struct B is nothrow move constructible? "
<< is_nothrow_move_constructible<B>::value
<< endl;
// Check if struct C is no throw
// move constructible or not
cout << "struct C is nothrow move constructible? "
<< is_nothrow_move_constructible<C>::value
<< endl;
// Check if struct D is no throw
// move constructible or not
cout << "struct D is nothrow move constructible? "
<< is_nothrow_move_constructible<D>::value
<< endl;
return 0;
}
输出:
int:true char:true float:true struct A is nothrow move constructible? true struct B is nothrow move constructible? true struct C is nothrow move constructible? false struct D is nothrow move constructible? false
参考: http://www.cplusplus.com/reference/type_traits/is_nothrow_move_constructible/
相关用法
- C/C++ fseek()用法及代码示例
- C++ std::search_n用法及代码示例
- C++ tellg()用法及代码示例
- C++ wcstok()用法及代码示例
- C++ wcsstr()用法及代码示例
- C++ wcsncpy()用法及代码示例
- C++ forward_list::cend()用法及代码示例
- C++ std::is_destructible用法及代码示例
- C++ std::is_trivially_default_constructible用法及代码示例
- C++ std::numeric_limits::digits用法及代码示例
- C++ std::remove_cv用法及代码示例
- C++ std::underlying_type用法及代码示例
注:本文由纯净天空筛选整理自bansal_rtk_大神的英文原创作品 std::is_nothrow_move_constructible in C++ with Example。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。