title: Can I rely on std::map::operator[] to touch?
body: <p>I have a C++ program in which I want to insert default values for any keys missing in a <code>std::map</code>. I'm thinking the easiest way to do this would be to use <code>std::map::operator[]()</code> like the POSIX touch command - that is, to leave the value unchanged if it already exists, but to create it if it doesn't. For <a href="http://ideone.com/jZJboQ">example</a>,</p>
  
  <pre><code>#include &lt;map&gt;
  #include &lt;vector&gt;
  #include &lt;iostream&gt;
  
  using namespace std;
  
  int main()
  {
      vector&lt;int&gt; keys = {0, 1};
  
      map&lt;int, int&gt; m;
      m[1] = 5;
      m[2] = 12;
  
      for (const int i : keys)
      {
          m[i]; // touch value
      }
  
      for (auto const &amp; kv : m)
      {
          cout &lt;&lt; kv.first &lt;&lt; ", " &lt;&lt; kv.second &lt;&lt; endl;
      }
  }
  </code></pre>
  
  <p>Can I be sure that the compiler won't optimize out the <code>m[i];</code> statements, since I'm not "doing" anything with them? (Not explicitly assigning to, not reading from.)</p>