Is the size [test] guaranteed to be 10 at the end of this sequence?
Yes. In the last line of your code, the value of size[test] initializes the T() element, or in this case size_t() :
C ++ 11 23.4.4.3 access to the map element [map.access]
T& operator[](const key_type& x) ;
1 Effects: If there is no key equivalent to x on the card, inserts the value__name (x, T () ) into the card.
As for T() , the exact language is somewhat involved, so I will try to bring the corresponding bits:
C ++ 11 8.5.16 The semantics of initializers is as follows.
- If the initializer is (), the object is initialized with a value.
8.5.7 For value-initialize, an object of type T means:
- if T is a class of a class (possibly cv-qualit) ...
- if T is a (possibly cv-qualified) non-unit class ...
- if T is an array type, then each element is initialized with a value;
- , otherwise the object is initialized to zero.
8.5.5 For zero initialization, an object or reference of type T means:
- if T is a scalar type (3.9),, the object is set to 0 (zero) , taken as an integral constant expression, converted to T;