Are there alternatives to C ++ metaprogramming besides templates?

I use metaprogramming quite a lot, but sometimes a combination of macros and c templates is simply not enough.

I believe that the disadvantage could potentially be the lack of cross-platform compatibility if the metaprogramming platform is designed only for, say, Linux, etc.

So yes, is there such a thing right now besides templates? At Google, metaprogramming is dominated by metaprogramming of templates, so it’s hard to find right now.

edit : here is an example of what I was working on.

Suppose I have a general class for saving / loading files to and from buffers. Let me call it FilePack.

I have a define macro that looks like

  defineFilePack(BaseClass, "code-a")

It basically creates a class called "BaseClassPack", which is defined as a subclass. That's what.

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, in fact, there is a built-in check by the FilePack constructor that the declared code matches the size using the global map.

Currently, I don’t understand how to do this using template metaprogramming, which is actually well suited for it, because all these file codes are stored in the source file. Of course, someone might possibly make their own FilePack at runtime, but that's beyond the point.

, , FilePack. , PersonDetails.. , - , , , FilePack , PersonDetails .

, , - , ?

+5
5

.

. , lex/yacc Qt MOC.

+5

. , , , Boost Preprocessor, , .

, , .

+2

, ,

  • .
  • .
  • ( , )
  • ++ ++, , .
  • , , , , .

, , ++, - , , - , , .

, ParcPlace ?

Hm, , - .: -)

hth.,

+2

, , , Python. , , , ( ).

++ - - ++... ( , ?).

Python - ...

"" ++, ...

//
// U8 -> F32 format converter
//
//    - src(Image:U8) ............ source image
//    - dst(pImage:F32:src) ...... destination image
//
ImgFilter u8_to_f32(Image& src, Image& dst)
{
    const double k = 1.0/255;
    for (int y=0; y<src.h; y++)
    {
        unsigned char *rp = src.u8(0, y);
        float *wp = dst.f32(0, y);
        for (int x=0,w=src.w; x<w; x++)
            *wp++ = *rp++ * k;
    }
}

/ python script, .h , ++, , , , python. , "" . Python script 200 , ++ .

+1

, , . / , , .

DMS Software Reengineering Toolkit - . , . DMS , (Jackpot - Java) , ++ Front End ++.

DMS , , , ++, ( radix ..). , AST. , - , , , .

0

All Articles