Do you have to sort the vector in-place? You anyway need to convert the original vector to an unordered set, for performance reasons. So, you might as well empty the original vector and use it.