This problem reminds me of a recent paper written by Bjarne Stroustrup (and others) describing and evaluating a technique named generalized hoisting. Its applied to the C++ STL iterators and removes lot of code bloat and increase performances surprisingly. I found it a great read (as often with Bjarne.S) I thought you may find it interesting too. It says the ideas apply to the D language too.
Minimizing Dependencies within Generic Classes for Faster and Smaller Programs. http://www.research.att.com/~bs/SCARY.pdf
