Fix clang/OS X sorting iterators and add a simple test