After writing:
std::pair<int, int> x;
Am I guaranteed that x.first and x.second are both zero? Or could they have any value?
The reason why I care is because I’m trying to determine whether a map whose values are pointers is guaranteed to return NULL if I access an element that’s not in the map. I.e., if I do:
std::map<int, void*> my_map;
std::cout << int(my_map[5]) << std::endl;
then am I guaranteed to get zero (NULL)? Or is the behavior undefined?
Yes, that guarantee holds true. Quoting the C++11 standard, §20.3.2/2-3:
And §8.5/7:
And lastly, §8.5/5: