The declaration for the [] operator on a std::map is this:
T& operator[] ( const key_type& x );
Is there a reason it isn't this?
T& operator[] ( const key_type& x );
const T& operator[] const ( const key_type& x );
Because that would be incredibly useful any time you need to access a member map in a const method.
See Question&Answers more detail:os