Is there a compile-time func/macro to determine if a C++0x struct is POD?

后端 未结 1 611
时光说笑
时光说笑 2020-12-31 00:05

I\'d like to have a C++0x static_assert that tests whether a given struct type is POD (to prevent other programmers from inadvertently breaking it with new members). ie,

相关标签:
1条回答
  • 2020-12-31 01:02

    C++0x introduces a type traits library in the header <type_traits> for this sort of introspection, and there is an is_pod type trait. I believe that you would use it in conjunction with static_assert as follows:

    static_assert(std::is_pod<A>::value, "A must be a POD type.");
    

    I'm using ISO draft N3092 for this, so there's a chance that this is out of date. I'll go look this up in the most recent draft to confirm it.

    EDIT: According to the most recent draft (N3242) this is still valid. Looks like this is the way to do it!

    0 讨论(0)
提交回复
热议问题