Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Erase elements from multimap, based on key values?

How would I erase all elements from an std::multimap who have a key less than or equal to 20?

I know how to erase, I don't know how to pass in the condition "key less than 20".

like image 729
user997112 Avatar asked Mar 10 '23 09:03

user997112


1 Answers

The next code should work:

std::multimap<int, int> M;
// initialize M here
auto it = M.upper_bound(20);
M.erase(M.begin(), it);

Just use upper_bound and then erase.

like image 156
Edgar Rokjān Avatar answered Mar 20 '23 12:03

Edgar Rokjān