Quoth the standard:
ISO/IEC 14882 §23.4.4.3
T& operator[](const key_type& x);
- Effects: If there is no key equivalent to
x
in the map, inserts value_type(x, T())
into the map.
- Requires:
key_type
shall be CopyConstructible
and mapped_type
shall be DefaultConstructible
.
- Returns: A reference to the
mapped_type
corresponding to x
in *this
.
- Complexity: logarithmic.
So, not only is it guaranteed, but evaluating myMap["Hey"]
also causes the value 0 to be inserted into the map, if there was no entry for it before.