title: How to create a std::map of constant values which is still accessible by the [] operator?
body: <p>I need a std:map data structure that is read only, which means I have to fill it once with data and then only read those values, never change them or add additional ones. </p>
  
  <p>My non-const version looks like this:</p>
  
  <pre><code>//in .h
  #include &lt;string&gt;
  #include &lt;map&gt;
  
  std::map&lt;std::string, int&gt; myMap;
  void initMap();
  
  //in .cpp
  #include "foo.h"
  
  void initMap() {
    myMap["Keys"] = 42;
  }
  </code></pre>
  
  <p>Then I'd call <code>initMap()</code> once in my code and be done.</p>
  
  <p>Now I've read several questions here already and it seems non-trivial to achieve const-ness for the map.</p>
  
  <p>Making it a <code>std::map&lt;std::string, const int&gt;</code> won't allow me to fill it in the <code>initMap()</code>.
  Filling it with a non-const temp and the copy constructor on definition doesn't work either, as the copy constructor doesn't easily take the non-const version as input.</p>
  
  <p>Making it a <code>const std::map&lt;std::string, int&gt;</code> (which I could fill with a non-const copy during definition) would disable the use of the <code>[]</code> operator for value access.</p>
  
  <p>So is there a way to achieve (value) const-ness and initialize the structure (preferably in the header file)?</p>
  
  <p>BTW: Neither C++0x nor C++11 nor <code>boost::</code> is an option.</p>