Can metaprogramming patterns be used to transform any structure or class into a tuple?
For instance:
struct Foo { char c; int i; std::string s; }; typedef std::tuple< char, int, std::string > Foo_Tuple;
It would be nice to have a template code that will automatically generate Foo_Tuple for me.
ANSWER
This is an unnecessary case for such a simple case, but for more complex cases (for example, ORM or at any time when you need to write a lot of boiler room code, and a simple template or macro is not suitable for the task), Boost Mirror looks very useful. I delved into Boost Mirror a little more: the main reflection functions (in the mirror and puddle) are not difficult to understand, they are quite easy to configure and seem to be quite extensive (you can handle many constructions, including C ++ 11 enum classes, etc. .). I believe that this basic functionality is more than sufficient - I can just use MACRO to the extent that I want to show my Reflection classes (so I do not need to write boiler room code). Factory generators also seem very powerful (with the same initial macro settings, you can swap places in any Factory generator that you like to output JSON, SOCI or to a stream, etc.), but it has a larger learning / tuning curve if You want to write your own Factory Generators. One last couple of notes: with some minor tricks, I was able to get it working with C ++ 11 on gcc 4.7.2; In addition, the documentation was well-voiced, and there seemed to be more than enough examples for a quick transition.
source share