Provide template functions in separate header

Template functions must be defined in the header since the library
cannot contain generic code. To keep only the interface in the main
header, all such function bodies are put in a separate _impl file.