1stable_sort() can be used instead. It’s guaranteed not to reorder equal elements.