简体   繁体   English

在尝试删除元素之前,是否需要检查unordered_set是否包含元素?

[英]Do we need to check if an unordered_set contains an element before trying to erase it?

Say I have a set: 说我有一套:

std::unordered_set<int> mints;

Then I do: 然后我做:

mints.erase(foo);

But mints doesn't contain foo! 但是薄荷糖不包含foo! Is it guaranteed that nothing bad will happen, and that erase will simply just return 0 ? 是否保证不会发生任何不良情况,并且擦除将仅返回0?

如果您通过用erase( const key_type& key )获得了重载的erase() ,并且该键不存在,则不会发生任何不良情况,这将是一个无操作,并且erase()将返回0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM