我想有一個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