< type_traits >头文件中提供了C++ STL的std :: is_destructible模板。 C++ STL的std :: is_destructible模板用于检查T是否可破坏。一个类称为可破坏类,其析构函数不会被删除,并且在派生类中可能会被访问。如果T是可销毁类型,则返回布尔值true,否则返回false。
头文件:
#include
模板类别:
template< class T >
struct is_destructible;
句法:
std::is_destructible::value
参数:模板std :: is_destructible接受单个参数T(特质类)以检查T是否为可破坏类型。
返回值:模板std :: is_destructible返回一个布尔变量,如下所示:
- 正确:如果类型T是可破坏的类型。
- False:如果类型T不是可破坏的类型。
下面是演示C++中std :: is_destructible的程序:
程序:
// C++ program to illustrate
// std::is_destructible
#include
#include
using namespace std;
// Declare a structures
struct X {
};
struct Y {
// Destructors
~Y() = delete;
};
struct Z {
~Z() = default;
};
struct A : Y {
};
// Driver Code
int main()
{
cout << boolalpha;
// Check if int is destructible
// or not
cout << "int is destructible? "
<< is_destructible::value
<< endl;
// Check if float is destructible
// or not
cout << "float is destructible? "
<< is_destructible::value
<< endl;
// Check if struct X is
// destructible or not
cout << "struct X is destructible? "
<< is_destructible::value
<< endl;
// Check if struct Y is
// destructible or not
cout << "struct Y is destructible? "
<< is_destructible::value
<< endl;
// Check if struct Z is
// destructible or not
cout << "struct Z is destructible? "
<< is_destructible::value
<< endl;
// Check if struct A is
// destructible or not
cout << "struct A is destructible? "
<< is_destructible::value
<< endl;
return 0;
}
输出:
int is destructible? true
float is destructible? true
struct X is destructible? true
struct Y is destructible? false
struct Z is destructible? true
struct A is destructible? false
参考: http://www.cplusplus.com/reference/type_traits/is_destructible/
要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程” 。