Finishes type-based template specialization.

Yet to do template functions, but I am very happy with the performance of the existing template code.

This should be done in a few more commits.