title: C++ map access discards qualifiers (const)
body: <p>The following code says that passing the map as <code>const</code> into the <code>operator[]</code> method discards qualifiers:</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;map&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  class MapWrapper {
  public:
      const int &amp;get_value(const int &amp;key) const {
          return _map[key];
      }
  
  private:
      map&lt;int, int&gt; _map;
  };
  
  int main() {
      MapWrapper mw;
      cout &lt;&lt; mw.get_value(42) &lt;&lt; endl;
      return 0;
  }
  </code></pre>
  <p>Is this because of the possible allocation that occurs on the map access? Can no functions with map accesses be declared const?</p>
  <pre><code>MapWrapper.cpp:10: error: passing const std::map&lt;int, int, std::less&lt;int&gt;,
  std::allocator&lt;std::pair&lt;const int, int&gt; &gt; &gt; as this argument of 
  _Tp&amp; std::map&lt;_Key, _Tp, _Compare, _Alloc&gt;::operator[](const _Key&amp;) 
  [with _Key = int, _Tp = int, _Compare = std::less&lt;int&gt;, 
  _Alloc = std::allocator&lt;std::pair&lt;const int, int&gt; &gt;] discards qualifiers
  </code></pre>