mardi 21 juillet 2015

How can I pretty-print a struct with its fields being named?

Suppose I have a

struct foo { int bar; double baz; };

And a struct foo s; somewhere. I would like to be able to write magic(s) and get a string, or text printed to cout, which includes not just the values of s.bar and s.baz, but also the identifiers 'bar' and 'baz'.

I know C++ doesn't have proper reflection, but maybe something RTTIish (I'm not well-versed in RTTI)? Or perhaps with some minor decoration of the class declaration?





Aucun commentaire:

Enregistrer un commentaire