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;
FilePack(const string& thecode, int bufsize);
void operator=(FilePack& rhs);
void saveToFile(const string& filename);
void loadFromFile(const string& filename);
};
class PersonDetails{
public:
solidstring<64> name;
int age;
DateTime birthday;
};
defineFilePack(PersonDetails, "psd")
class PersonDetailsPack : public FilePack{
public:
PersonDetailsPack():
FilePack("psd", sizeof(PersonDetails)){
}
PersonDetails& get(){
return *(PersonDetails*)getBuffer();
}
};
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 .
, , - , ?