My use case:
map cars;
bool exists(const string& name) {
// somehow I should find whether my MAP has a car
// with the name provid
Sure, use an iterator
map<string,Car>::const_iterator it = cars.find(name);
return it!=cars.end();
This does not answer the question but it might be good to know. You can know if it exists by erasing it.
bool existed = cars.erase( name );
You could also use
bool exists(const string& name) {
return cars.count(name) != 0;
}
return cars.find(name) != cars.end();
C++20:
return cars.contains(name);