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:
Vadim Zeitlin 2021-12-04 17:34:58 +01:00
commit 628e2cf6d2
2 changed files with 3 additions and 3 deletions

View file

@ -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();
}
}

View file

@ -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;
}
}