我想有一个C++ 0x static_assert测试给定的结构类型是否为POD(以防止其他程序员无意中将其与新成员分开)。即,是否有编译时func /宏来确定C++ 0x结构是否为POD?
struct A // is a POD type
{
int x,y,z;
}
struct B // is not a POD type (has a nondefault ctor)
{
int x,y,z;
B(int _x, int _y, int _z) : x(_x), y(_y), z(_z) {}
}
void CompileTimeAsserts()
{
static_assert(is_pod_type(A) , "This assert should not fire.");
static_assert(is_pod_type(B) , "This assert will fire and scold whoever added a ctor to the POD type.");
}
是否有某种is_pod_type()
宏或内部我可以在这里使用?我在任何C++ 0x文档中找不到一个,但是当然,0x上的网络信息仍然相当零碎。
请注意,在C++ 0x中,struct B不是POD,因为它没有*简单的默认构造函数*(请参阅N3242中的9.0.10和9.0.6)。我不确定什么算作一个简单的默认构造函数(见12.1.5),但怀疑添加'B()= default;'可能会将struct B转换为C++ 0x POD。 – Sjoerd