Quick Q: Why does std::map not have a const accessor? -- StackOverflow
To help balance out "introductory," "intermediate," and "advanced" content, we're trying an experiment to highlight interesting bite-sized tidbits that are in the first two categories.
Here's today's tidbit from StackOverflow's [c++11] tag:
The declaration for the
[]operator on astd::mapis 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
constmethod.
As the two top answers show, the answer is different in C++98 and C++11, and C++11 is where it's "at" (pardon).

A C++11 Name-Lookup Problem: a Long-Term Solution and a Temporary Work-Around

On vector<bool>