On 2013-06-17 17:30, Daryle Walker wrote:
If you don't mind, why do you want to do pack structs in the first place? Most people cringe at the thought of packing-specific code.
I've read about using an array segment of complex numbers as an array of real numbers (but twice as long) for stuff like Fourier transforms. At http://en.cppreference.com/w/cpp/numeric/complex#Non-static_data_members, the effect is documented for std::complex (at least for float/double/long-double). I want to simulate the effect.
template < typename T, unsigned R > struct complex_it { T c[ 1ULL << R ]; };
The above class template will be standard-layout if "T" is; that mandates no starting padding. Array elements are packed. So I can do the array-segment translation only if there's no trailing padding. In contrast:
template < typename T, unsigned R > struct complex_rt;
template < typename T > struct complex_rt
{ T r; }; template < typename T, unsigned R > struct complex_rt { complex_rt
b[2]; }; will have padding all over the place if there's any trailing padding at a lower level.
I wouldn't expect any padding in such structures, because at core they're just a sequence of Ts. Perhaps you could simply verify no padding by static_assert on the size, and not worry about it unless that assertion ever fires? John Bytheway