C++ Any way to programmatically detect POD-struct?

I have data structure which stores POD-structs (each instantiation stores a single type only, since it is basically an array of a specific POD-struct). Sometimes another dev. will modify one of these structs, adding or modifying a data type. If a non-POD element is added, e.g. std::string, the data structure blows-up at runtime, because the memory model changes. Is there any way to detect if a class or struct is POD-compliant using compiler defines or a call at run-time (to avoid this maintainence issue) ? I'm using g++ (GCC) 4.2.4.

-------------Problems Reply------------

At runtime probably not, but at compile time, you can use is_pod trait from either C++0x standard library or Boost.TypeTraits.

static_assert(std::is_pod<YourStruct>::value);

You can probably use boost type_traits library and in particular boost::is_pod<T>::value in an static assert.

If you don't have boost or C++0x then you can perhaps use some fact like that C++ does not let to use non-POD as member of union.

Category:c# Views:0 Time:2011-05-10
Tags: pod

Related post

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.174 (s). 11 q(s)