title: Why does setting an element of a map to its size increments the size *before* assigning it?
body: <p>This is a common pattern I use to index tokens as they come in: check if the token is in a map, and if not, add it to the map, assigning the map's size.</p>
  
  <p>When doing this in C++, it unexpectedly increments the map's size <em>before</em> the assignment is made:</p>
  
  <pre><code>#include &lt;cstdio&gt;
  #include &lt;map&gt;
  using namespace std;
  
  int main() {
      map&lt;char, int&gt; m;
      printf("Size before adding: %d\n", m.size());
      m['A'] = m.size();
      printf("Size after adding: %d\n", m.size());
      printf("What was added: %d\n", m['A']);
  
      return 0;
  }
  </code></pre>
  
  <p>This prints out:</p>
  
  <pre><code>Size before adding: 0
  Size after adding: 1
  What was added: 1
  </code></pre>
  
  <p>The way I understand it, it should evaluate the right hand side, which is zero, then pass it to a function that puts 'A' and the zero into the map. But it seems to be evaluating it after it started assigning, which doesn't make sense.</p>
  
  <p>Shouldn't the right-hand side be evaluated before the assignment operation?</p>