This example is built on top of nlohmann json, and provides a moderately lightweight solution for registering members of serializable objects.
This system has the following drawbacks, however:
- It is not
constexpr, and cannot be, because it usesstaticvariables inside functions when creating the serialization tables. - It is not threadsafe, although it probably could be
- It requires the user to wrap the name of any member that should be serialized in a macro:
struct Foo {
// Tell the system that hello should be serialized
int SERIALIZE(hello);
int SERIALIZE(world) = 60;
};- It does not handle pointers, although it could be extended to do so in some cases