类模板
<type_traits>
std::is_trivially_destructible
template <class T> struct is_trivially_destructible;
is trivially destructible
用于识别Tis a trivially destructible type.
Trivially destructible types include scalar types, trivially copy constructible classes and arrays of such types.
A trivially destructible class is a class (defined with类, structor联合体定义)
- uses the implicitly defined destructor.
- the destructor is not virtual.
- its base class and non-static data members (if any) are themselves also trivially destructible types.
要放回的字符的is_trivially_destructible类继承自integral_constant,其值为true_type或false_type,取决于Tis trivially destructible.
模板参数
- T
- 一个完整类型,或者void(可能带 cv 限定),或者一个未知边界的数组。
示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
// is_trivially_destructible example
#include <iostream>
#include <type_traits>
struct A { };
struct B { ~B(){} };
int main() {
std::cout << std::boolalpha;
std::cout << "is_trivially_destructible:" << std::endl;
std::cout << "int: " << std::is_trivially_destructible<int>::value << std::endl;
std::cout << "A: " << std::is_trivially_destructible<A>::value << std::endl;
std::cout << "B: " << std::is_trivially_destructible<B>::value << std::endl;
return 0;
}
|
输出
is_trivially_destructible:
int: true
A: true
B: false
|