I\'m trying to create a map inside a map:
typedef map inner_map;
typedef map outer_map;
Will I be ab
The value_type
a map is a pair and therefore it has members first and second. As with all iterators, a map iterator is a pseudo-pointer, i.e. it points to data within a collection and not copies of that data.
It is almost certain internally to contain pointers rather than references due to the fact that iterators can be re-assigned (that is what you use them for) and you cannot reassign references to refer to other objects.
Even if you have a const_iterator and the type underneath is POD, it must have a pointer to it, in case someone does this:
map< int, int > m;
m.insert( make_pair( 1, 2 );
map::const_iterator citer = m.begin();
map::iterator iter = m.begin();
iter->second = 3;
std::cout << citer->second << '\n'; // should always print 3
The behaviour should be defined and should output 3, which would not happen if the const_iterator decided to "optimise" after all it's const and only int...