Is metaprogramming useful?

Sean Kelly sean at f4.ca
Tue Nov 28 10:03:01 PST 2006


Charles D Hixson wrote:
> 
> Of course, what would be really interesting would be a runtime version 
> of D, with runtime type assignment, etc., but without the kind of bloat 
> that would occur if this were done with templates.
> 
> (OTOH, I must admit that I'm guessing at the amount of bloat that a 
> generic template would add.  They don't add that much in Eiffel or Ada 
> code, but they were impossibly bloated the last time I tried it in C++ 
> [admittedly that's over a decade ago].)

Things have improved greatly, though actual results still vary widely 
from compiler to compiler.  Here's a link to the C++ performance report 
compiled a few years ago:

http://www.research.att.com/~bs/performanceTR.pdf

The crucial part of reducing code size is for the compiler to recognize 
that the code for many specializations is actually the same (pointers to 
different class types, for example), and to eliminate duplicates.  This 
can be done manually in library code as well (containers might use a 
thin wrapper on top of a more traditional class that stores values as 
void*), if the compiler optimizations are not sufficient.


Sean



More information about the Digitalmars-d mailing list