Separated template function definitions from header files

Moved the template function definitions to their own .txx files, which
are "#include"d in the header files.