What you want is special comparison and exchanging functionality. Even then, this sort of thing is not that uncommon.
In order to have it run-time configurable, you may be best to declare a comparator that takes a list of column IDs in its constructor, and whose () operator uses that accordingly. If you don't need to change the order the columns are sorted by at run-time then its even easier, and a very common thing to do.
Then it's just a matter of ensuring it swaps 'rows' correctly, probably via writing a custom swap function for your 'row' class.
Edited by iMalc, 06 April 2013 - 04:53 PM.
To clarify, it's not a special sorting algorithm you want, virtually all of them can do this. std::sort or std::stable_sort are fine for this.