I am defining a small function to create a histogram of a vector of integers, Initially I defined the following function that first test whether the key exists in the map be
This is a guarantee by the behavior of std::map's operator [] overload. If the key does not exist then it will be value-initialized for you. Since int, when value-initialized is assigned to zero, you're safe here.