Feb 162009
 

Since I’m doing a lot of C++ these days and working a lot with the STL, I want to jot down some things I’ve had to painfully recall about sorting:

  1. The std::sort function really only works with vector
  2. If you want to sort a set of pointers, you’ll need to create a comparator function or object and use it as a type parameter (uglier than hell)
  3. If you want to sort a list, you MUST call the sort method on the list

#2 looks like this and really sucks to look at:

And if you want to pass that thing around, you have to either pass it like that (nasty) or typedef it. Since I hate all typedefs, macrodefs, etc, I generally pass that nasty full type around.