I'm learning C++ and apparently a way of checking if a particular key exists in a std::map
is using the member function count
.
My first though was: Aren't the keys supposed to be unique? And checking the documentation indeed they are unique, so count will either return 0 or 1.
Isn't it a bit counter-intuitive to call it count
? Why not exist
?
To me count makes sense in a list where you expect a number of occurrences of an element, but if the method is only allowed to return 1 or 0 it doesn't make sense to me.
Am I missing something? Is there a reason to call it count
or it's just a bad naming?