How can I print the structure with the field names?
Suppose I have
struct foo { int bar; double baz; };
And struct foo s;
somewhere. I would like to write magic(s)
and get a string or text printed in cout that includes not only the s.bar and s.baz values, but also the "bar" and "baz" identifiers.
I know C ++ doesn't have proper reflection, but maybe something RTTIish (I'm not good at RTTI)? Or perhaps with a little decoration on the class declaration?
Note. Of course I'm asking for a solution that will work for any type, or at least any structure; i can implement operator<<
for foo
.
source to share
We may have to wait until C ++ adds expression to the language.
This is actively working WG7 SG7. What is it? WG21 is the International Organization for Standardization (ISO) working group that develops standards for the C ++ language. SG7 is the subgroup responsible for exploring opportunities.
SG7 has a Google Group discussing its current work.
source to share