tsvSelect does the primary work of the tsv-select program.

Input is read line by line, extracting the listed fields and writing them out in the order specified. An exception is thrown on error.

This function is templatized with instantiations for the different --rest options. This avoids repeatedly running the same if-tests inside the inner loop. The main function instantiates this function three times, once for each of the --rest options. It results in a larger program, but is faster. Run-time improvements of 25% were measured compared to the non-templatized version. (Note: 'cte' stands for 'compile time evaluation'.)