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?
Note: Of course I'm asking about a solution which would work for any type, or at least any struct; obviously I can implement an operator<<
for foo
's.
We may well have to wait until C++ get reflection facilities added to the language.
This is being actively worked on, by WG21 SG7. What's that? WG21 is the working group of the International Standards Organization (ISO) which develops the C++ language standards. SG7 is the sub-group in charge of exploring the possibilities reflection.
SG7 has a Google Group in which it discusses its ongoing work.