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

  • Home
  • SEARCH
  • 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 3692612
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:16:56+00:00 2026-05-19T04:16:56+00:00

I have been using metaprogramming quite a lot, but sometimes the combination of c

  • 0

I have been using metaprogramming quite a lot, but sometimes the combination of c macros and templates are just not enough.

I suppose the drawback would potentially be lack of cross-platform compatibility if the metaprogramming platform is only for, say, linux etc.

So yeah, is there such thing available right now, besides templates? Google search for metaprogramming is dominated by template metaprogramming, so it’s hard to find right now..

edit: here’s an example on something I’ve been working on.

Suppose I have a generic class for saving/loading files into and from buffers. Let’s call it FilePack.

I have a define macro, which looks like

  defineFilePack(BaseClass, "code-a")

It basically creates a class called “BaseClassPack”, which is defined to be a subclass. Below is that thing.

class FilePack{
   public:
      char * thebuffer;
      int bufsize;
      string packcode;

      // and constructors etc
      FilePack(const string& thecode, int bufsize);
      void operator=(FilePack& rhs);
      void saveToFile(const string& filename);
      void loadFromFile(const string& filename);
      // .. and all the function you'd expect to see in a class like this

};

// the person details

class PersonDetails{
   public:
      solidstring<64> name;
      int age;
      DateTime birthday;
      // .. yada yada yada
};


defineFilePack(PersonDetails, "psd")

// the above creates the following class

class PersonDetailsPack : public FilePack{
   public:
      PersonDetailsPack():
         FilePack("psd", sizeof(PersonDetails)){ // etc

      }

      PersonDetails& get(){
         return *(PersonDetails*)getBuffer();
      }

      // and a lot more convenience function

};

Now, there’s actually an in-built check by FilePack’s constructor that the declared code matches with the size, using a global map.

Right now I’m stumped on how to do that using template metaprogramming, which is actually a good fit for it because all of these filepack codes are declared inside the source file. Sure, someone can probably make their own FilePack in run-time, but that’s besides the point.

Another thing that metaprogramming could help with here is to support loading different versions of FilePack. Suppose I had to update the PersonDetails class.. I just make a new class, use some kind of metaprogramming to declare the inheritance, and magically make FilePack know so that when it’s loading an old version of PersonDetails it can call the conversion function, or whatever.

Also, you’re welcome to comment on that architecture, and I’m keen to hear any comments about it, but it might be a bit off-topic?

  • 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-05-19T04:16:57+00:00Added an answer on May 19, 2026 at 4:16 am

    You can also metaprogram with the preprocessor.

    You could consider using special purpose preprocessors to generate code as “metaprogramming” as well. Then you could include things like lex/yacc and the Qt MOC.

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

Sidebar

Related Questions

We have been using CruiseControl for quite a while with NUnit and NAnt. For
I have been using Castle MonoRail for the last two years, but in a
I have been using ASP.NET for years, but I can never remember when using
I have been using PHP and JavaScript for building my dad's website. He wants
I have been using Eclipse as an IDE for a short amount of time
We have been using Scrum for around 9 months and it has largely been
I have been using C# for a while now, and going back to C++
I have been using Ruby for a while now and I find, for bigger
I have been using IoC for a little while now and I am curious
I have been using the CSLA framework for couple of years now for windows

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.