A little while back a friend of mine and I were talking about serialization of
struct
objects as raw bytes. He was working with generated objects that contain
padding, but the objects needed to be serialized without the padding; for
example:
struct Foo
{
char data0;
// 3 bytes padding here
int data1;
};
In the case he described, there are dozens of object types that need to be
serialized, and all are:
- Generated by his organization (so they can’t be modified), and
- Are guaranteed to be aggregates
Being a template meta-programmer, I thought it would be a fun challenge to try
to solve this in a generic way using c++17
– and in the process I
accidentally discovered a generic solution for iterating all members of
any aggregate type.
Continue reading…