std::is_destructible in C++ with Example
The std::is_destructible template of C++ STL is present in the <type_traits> header file. The std::is_destructible template of C++ STL is used to check whether the T is destructible or not. A class is called destructible whose destructor is not deleted and potentially accessible in derived classes. It return the boolean value true if T is destructible type, otherwise return false.
Header File:
#include<type_traits>
Template Class:
template< class T >
struct is_destructible;
Syntax:
std::is_destructible<T>::value
Parameter: The template std::is_destructible accepts a single parameter T(Trait class) to check whether T is destructible type or not.
Return Value: The template std::is_destructible returns a boolean variable as shown below:
- True: If the type T is a destructible type.
- False: If the type T is not a destructible type.
Below are the programs to demonstrate std::is_destructible in C++:
Program:
#include <bits/stdc++.h>
#include <type_traits>
using namespace std;
struct X {
};
struct Y {
~Y() = delete ;
};
struct Z {
~Z() = default ;
};
struct A : Y {
};
int main()
{
cout << boolalpha;
cout << "int is destructible? "
<< is_destructible< int >::value
<< endl;
cout << "float is destructible? "
<< is_destructible< float >::value
<< endl;
cout << "struct X is destructible? "
<< is_destructible<X>::value
<< endl;
cout << "struct Y is destructible? "
<< is_destructible<Y>::value
<< endl;
cout << "struct Z is destructible? "
<< is_destructible<Z>::value
<< endl;
cout << "struct A is destructible? "
<< is_destructible<A>::value
<< endl;
return 0;
}
|
Output:
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
Reference: http://www.cplusplus.com/reference/type_traits/is_destructible/
Last Updated :
12 Jun, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...