title: Why is this swap method not working?
body: <p>Why does the below two snippets of code have different results? I want to add a 1 in front of digits, which is a vector of integers. But the second snippet does not properly swap.</p>
  
  <pre><code>int tmpInt(1);
  for (int i=0; i&lt;digits.size(); i++){
      swap(tmpInt, digits[i]);
  }
  digits.push_back(tmpInt);
  </code></pre>
  
  <p>versus:</p>
  
  <pre><code>int tmpInt(1);
  for (auto it : digits){
      swap(tmpInt, it);
  }
  digits.push_back(tmpInt);
  </code></pre>