头文件:
#include
模板类别:
template
struct is_nothrow_copy_constructible
句法:
is_nothrow_copy_constructible::value
参数:模板std :: is_nothrow_copy_constructible接受单个参数T(Trait类),以检查T是否为可复制构造类型。
返回值:模板std :: is_nothrow_copy_constructible返回一个布尔变量,如下所示:
- 是:如果类型T是可复制构造类型。
- False:如果T类型不是可复制构造类型。
下面是演示C++中std :: is_nothrow_copy_constructible的程序:
程序1:
// C++ program to illustrate
// std::is_nothrow_copy_constructible
#include
#include
using namespace std;
// Define Classes
class X {
};
class Y {
Y(const Y&) {}
};
// Driver Code
int main()
{
cout << boolalpha;
// Check if int is no throw copy
// constructible
cout << "int: "
<< is_nothrow_copy_constructible::value
<< endl;
// Check if class X is no throw copy
// constructible
cout << "class X: "
<< is_nothrow_copy_constructible::value
<< endl;
// Check if class Y is no throw copy
// constructible
cout << "class Y: "
<< is_nothrow_copy_constructible::value
<< endl;
return 0;
}
输出:
int: true
class X: true
class Y: false
程式2:
// C++ program to illustrate
// std::is_nothrow_copy_constructible
#include
#include
using namespace std;
// Declare structures
struct A {
};
struct B {
B(const B&) {}
};
struct C {
C(const C&)
noexcept {}
};
// Driver Code
int main()
{
cout << boolalpha;
cout << "is_nothrow_copy_constructible:"
<< endl;
cout << "int is_nothrow_copy_constructible? "
<< is_nothrow_copy_constructible::value
<< endl;
cout << "A is_nothrow_copy_constructible? "
<< is_nothrow_copy_constructible::value
<< endl;
cout << "B is_nothrow_copy_constructible? "
<< is_nothrow_copy_constructible::value
<< endl;
cout << "C is_nothrow_copy_constructible? "
<< is_nothrow_copy_constructible::value
<< endl;
return 0;
}
输出:
is_nothrow_copy_constructible:
int is_nothrow_copy_constructible? true
A is_nothrow_copy_constructible? true
B is_nothrow_copy_constructible? false
C is_nothrow_copy_constructible? true
参考: http://www.cplusplus.com/reference/type_traits/is_nothrow_copy_constructible/
要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程” 。