c++stlmultiset

In std::multiset is there a function or algorithm to erase just one sample (unicate or duplicate) if an element is found


Perhaps this is a duplicate but I did not find anything searching: When erase(value) is called on std::multiset all elements with the value found are deleted. The only solution I could think of is:

std::multiset<int>::iterator hit(mySet.find(5));
if (hit!= mySet.end()) mySet.erase(hit);

This is ok but I thought there might be better. Any Ideas ?


Solution

  • Since C++17 (see here):

    mySet.extract(val);