3 ms·
Or any language where you can write code that generates code at compile time, like Nim. Unfortunately, any answer for C++ is unlikely to be so elegant, so prep
by stevedonovan 11y ago
Or any language where you can write code that generates code at compile time, like Nim. Unfortunately, any answer for C++ is unlikely to be so elegant, so preprocessing feels like a lesser evil.
- Animats 11y agoIf you had some way to apply templates to each element of a structure in sequence, you could use template metaprogramming to do marshalling. Suppose you could write struct pnt { float x; float y; bool valid; }; pnt p; and then have auto s = serialize(p); expand into auto s = serialize_field("x", p.x, serialize_field("y", p.y, serialize_field("valid", p.valid))) then serialization could be implemented by defining serialize_field for each type.