Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8990621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:32:20+00:00 2026-06-15T22:32:20+00:00

Is it possible to use template meta-programming to convert any struct or class into

  • 0

Is it possible to use template meta-programming to convert any struct 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 some template code which will generate Foo_Tuple automagically for me.

ANSWER

This is overkill for such a simple case, but for more elaborate cases (eg ORM or any time you need to write a lot of boiler-plate code, and a mere template or macro is inadequate for the task), Boost Mirror looks like it may be extremely useful. I have dug into Boost Mirror a bit more: the basic reflection functionality (in Mirror and Puddle) are not hard to understand, are quite easy to set-up and seem to be quite extensive (can handle many constructs, including C++11 enum classes, etc…). I find this basic functionality to be more than adequate – I can just use the MACROS to the extent that I want to expose my classes to Reflection (so that I don’t have to write boiler-plate code). The Factory generators also seem to be very powerful (with the same initial macros set up, you can swap in any factory generator you like to output JSON, SOCI, or to a stream etc…), but has a larger learning curve/setup, if you want to write your own factory generators. One last couple of notes: with some minor tweaks, I was able to get it to work with C++11 on gcc 4.7.2; also, the documentation has been well DOxygenated and there seem to be more than sufficient examples to get going quickly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T22:32:22+00:00Added an answer on June 15, 2026 at 10:32 pm

    I don’t think that there’s a way to do this in C++.

    I don’t know a way to enumerate the fields/types in a struct – if you could do that, I would think that constructing such a tuple would be fairly straightforward.

    I believe that Boost.Fusion has a macro that helps with this called FUSION_ADAPT_STRUCT, but that’s all manual.

    The technical term for this is “reflection”, and you can find lots of information about it by searching for “C++ reflection”.

    Here’s one such article: How can I add reflection to a C++ application?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to use member function pointers with template meta-programming? Such as: class
I can use partial template specialization inside class declaration template<class T1, class T2> struct
Is it possible to use a data template for a single item with no
Is it possible to actually use the type passed as a template for control
Possible Duplicate: How to use enable_if to enable member functions based on template parameter
is it possible to use an external Template in KnockoutJS like this? <script type=text/html
Is it possible to use the using declaration with template base classes? I have
Is it possible to use the C++11 initializer_list to assemble a recursively defined class
This question requires knowledge of C++ template meta-programming as (indirectly) expression templates are involved.
Is it possible to use ack to search for content within Smarty template files

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.