Make std::{set,map} has() and has_key() methods const
They don't modify the object, so should be callable on const objects.
This commit is contained in:
parent
c4187f495f
commit
628e2cf6d2
2 changed files with 3 additions and 3 deletions
|
|
@ -52,8 +52,8 @@ namespace std {
|
|||
else
|
||||
throw std::out_of_range("key not found");
|
||||
}
|
||||
bool has_key(const K& key) {
|
||||
std::map< K, T, C >::iterator i = self->find(key);
|
||||
bool has_key(const K& key) const {
|
||||
std::map< K, T, C >::const_iterator i = self->find(key);
|
||||
return i != self->end();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ namespace std {
|
|||
bool del(const T& item) {
|
||||
return self->erase(item) != 0;
|
||||
}
|
||||
bool has(const T& item) {
|
||||
bool has(const T& item) const {
|
||||
return self->count(item) != 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue