-
Notifications
You must be signed in to change notification settings - Fork 538
Open
Description
Exercise 1.3.5.2.3
Using ms.erase(v) to delete just one copy of value v from a multiset ms that may contain 0, 1, or more copies of v. (note the 0)
Given solution
ms.erase(ms.find(v));
Issue
std::multiset::find returns end() when ms has 0 copies of v.
std::multiset::erase exhibits undefined behaviour when the pos passed to it is end().
Correct solution
auto temp = ms.find(v);
if (temp != ms.end()) ms.erase(temp);
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels