I need to take a C++ vector with potentially a lot of elements, erase duplicates, and sort it. Looks like this code will do the trick: (Correction--it won't; next time I'll test before posting. Thanks for the feedback.)
vec.erase(
std::unique(vec.begin(), vec.end()),
vec.end());
std::sort(vec.begin(), vec.end());
Is it faster to erase the duplicates first (as coded above) or perform the sort first? If I do perform the sort first, is it guaranteed to remain sorted after std::unique is executed?
Or is there a more efficient way to do all this?