I
int2str
Hi!
Given the following code:
#include <map>
#include <string>
#include <cassert>
int main()
{
std::map< std::string, unsigned > my_map;
++my_map["Test"];
assert( my_map["Test"] == 1 );
}
Can I rely on the fact that the newly created map element with key
"Test" will be created with a value of 0?
Josuttis's "The C++ Standard Library" seems to indicate so (pg. 207).
The Standard briefly states (23.3.1.2 para 1):
T& operator[] (const key_type& x);
Returns: (*((insert(make_pair(x, T()))).first)).second
So it looks like the default constructor for T is called. For PODs like
"unsigned", does the default constructor (?) guarantee
0-initialization?
Thanks for your insights!
Cheers,
Andre
Given the following code:
#include <map>
#include <string>
#include <cassert>
int main()
{
std::map< std::string, unsigned > my_map;
++my_map["Test"];
assert( my_map["Test"] == 1 );
}
Can I rely on the fact that the newly created map element with key
"Test" will be created with a value of 0?
Josuttis's "The C++ Standard Library" seems to indicate so (pg. 207).
The Standard briefly states (23.3.1.2 para 1):
T& operator[] (const key_type& x);
Returns: (*((insert(make_pair(x, T()))).first)).second
So it looks like the default constructor for T is called. For PODs like
"unsigned", does the default constructor (?) guarantee
0-initialization?
Thanks for your insights!
Cheers,
Andre