Why there is no std::erase?

  • A+
Category:Languages

I am a newbie in c++. While reading the STL I realized that there is no std::erase provided. I am not really sure why it is not there. A valid use case is following

std::vector<int> odd { 1, 3, 5, 3, 9, 11, 5, 17 }; std::sort(odd.begin(), odd.end()); std::erase(std::unique(odd.begin(), odd.end()), odd.end()); 

It is embedded in every container though. If performance is the reason, in a manner that if the objects are contiguous they could be deleted in one shot. But I guess that is doable with help template specialization.

 


How would it work? It only accepts a pair of iterators. Iterators don't have to keep a reference to their container (a vector's iterators can be mere aliases for pointers).

So how would the algorithm modify the container itself? It needs that access.

It must be a member function.

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: