Few ideas to reduce template bloat

Walter Bright newshound1 at digitalmars.com
Sun Mar 28 13:57:41 PDT 2010


bearophile wrote:
> Just to be sure you have understood: the solution number 5 is for a
> statically compiled language. It doesn't need a JIT. You just need normal
> objects, a virtual table, etc.

With enough indirection, template instances can all be done with one function 
regardless of the actual argument types. What is lost with that approach, 
however, are all the benefits of inlining, constant folding, specialization, 
etc. In addition, CPUs tend to do a much poorer job with indirection than they 
do with inline code.

D's templates are also more powerful than generics in that they can be used to 
templatize data and symbols, not just functions and classes.

Generic types can also be more bloated because they have to carry around the 
indirect references, while templated types can specialize them away. For 
example, a templated hash-map can often eliminate storing the hash, while a 
generic one will have to keep it regardless.



More information about the Digitalmars-d mailing list