I was doing a simple map program but ended up with this question. The c++ doc says this:
Access element If k matches the key of an element in the container, the func
Map values are value-initialized by the operator[]
, which, for int
means zero-initialization.
As defined by the standard (§23.4.4.3):
Effects: If there is no key equivalent to x in the map, inserts
value_type(x, T())
into the map.
T()
is explained as (§8.5/10):
An object whose initializer is an empty set of parentheses, i.e.,
()
, shall be value-initialized
which means (§8.5/8):
To value-initialize an object of type
T
means:[...]
— otherwise, the object is zero-initialized.
and zero-initialization is defined as (§8.5/6):
To zero-initialize an object or reference of type
T
means:— if T is a scalar type, the object is set to the value 0 (zero), taken as an integral constant expression, converted to
T
[...]
all quotes taken from n4140