Alex Rivera | Logout

std::set<T>::erase(key). What if key isn't there?

Asked 2010-12-24T10:40:00.857
21

if I erase an element from an std::set and pass the key, not the iterator, and the key isn't in the set right now, will an exception be thrown? The thing is every second sentence in the MSDN documentation says: "this does blah blah, but it doesn't conform to the standard". So I need to know the standard behaviour. I just couldn't find it in the standard. Redirecting to the relevant clause will do as well. Thanks.

Edit
Report

1 Answer

28
size_type erase ( const key_type& x );

Return value

The function returns the number of elements erased, which in set containers is 1 if an element with a value of x existed (and thus was subsequently erased), and zero otherwise.

(from set::erase)

answered 2010-12-24T10:43:10.030

Your Answer