mardi 14 avril 2020

Compile time check for changes to struct in C++

I have a serializable struct in struct.h that I am serializing in serialize.h using a custom serialization method. If a change is made to my serializable struct I need to make sure that a corresponding change in made in serialize.h as well.
Typical method of reflection use some macros for this. But the nature of our struct and the way we massage the data during serialization does not work well for this.

Is there some way to do some static compile time check so if the serializable struct is changed in any way without changing the serialize.h then the build will fail.

One way I have thought of but prefer to do it as last resort is to make a copy of definition of serializable struct in serialize.h and use boost::is_same check with error message asking for corresponding change in serialize.h





Aucun commentaire:

Enregistrer un commentaire