std::is_trivially_destructible来判断 一个 内置类型或structure/class/union类型 是否为 “容易销毁的(trivially destructible)”,从字面意思也可以看出,主要是check这个类型的 析构函数。官网给出如下解释:
A trivially destructible class is a class (defined with class, struct or union) that:
- 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.
如果一个类中的 非静态成员变量 是 not rivially destructible types,那么 这个类 也将是not rivially destructible types,std::is_trivially_destructible
在SystemC中,对于sc_bv 类型,由于其基类sc_bv_base有自定义析构函数,所以std::is_trivially_destructible>::value 返回false。
virtual ~sc_bv_base()
{ delete [] m_data;
}
参考:
is_trivially_destructible - C++ Reference
C++ std::is_trivially_destructible用法及代码示例 - 纯净天空
STL in C++11 (Allocator 2) - 简书
// execute:
//g++ -g -Wall -lsystemc -m64 -pthread main.cpp
//-L/$(your systemc path)/lib-linux64
//-I/$(your systemc path)/include-I/$(your systemc path)/src/tlm_utils -o sim#include // C++ program to illustrate
// std::is_trivially_destructible
#include
#include
using namespace std;
struct Y
{
Y(int, int){};
};
struct X
{
// Destructor
~X() noexcept(false)
{
}
};
struct Z
{
~Z() = default;
};
class A
{
virtual void fn() {}
};
class MyBvClass
{
sc_dt::sc_bv<2> m_test_mem;
};
int sc_main(int argc, char **argv)
{
cout << boolalpha;
cout << "int:"
<< std::is_trivially_destructible::value
<< endl;
cout << "struct X:"
<< std::is_trivially_destructible::value
<< endl;
cout << "struct Y:"
<< std::is_trivially_destructible::value
<< endl;
cout << "struct Z:"
<< std::is_trivially_destructible::value
<< endl;
cout << "class A:"
<< std::is_trivially_destructible::value
<< endl;
cout << "class MyBvClass:"
<< std::is_trivially_destructible::value
<< endl;
sc_core::sc_start();
return 0;
}
【C/C++|std::is_trivially_destructible】
推荐阅读
- 蓝桥杯学习|部分和(dfs)
- C/C++|项目实践—高并发内存池
- c/c++|这样学习C语言最有效(高级技巧)——共勉
- C/C++|轻松学做C语言课程设计(学生成绩管理系统-链表实现)
- c语言小知识点|实现C语言高效编程的四大秘技
- C/C++|关于linux下内存对齐的一些探究
- string|将中文数字转换成阿拉伯数字
- CMPSC473 Malloc Lab
- C/C++|C/C++ 文件读写