title: Range based loop: get item by value or reference to const?
body: <p>Reading some examples of range based loops they suggest two main ways<sup> <a href="http://en.cppreference.com/w/cpp/language/range-for">1</a>, <a href="http://allanmcrae.com/2012/05/c11-part-3-range-based-for-loops/">2</a>, <a href="http://www.cprogramming.com/c++11/c++11-ranged-for-loop.html">3</a>, <a href="http://en.wikipedia.org/wiki/C++11#Range-based_for-loop">4</a></sup></p>
  
  <pre><code>std::vector&lt;MyClass&gt; vec;
  
  for (auto &amp;x : vec)
  {
    // x is a reference to an item of vec
    // We can change vec's items by changing x 
  }
  </code></pre>
  
  <p>or</p>
  
  <pre><code>for (auto x : vec)
  {
    // Value of x is copied from an item of vec
    // We can not change vec's items by changing x
  }
  </code></pre>
  
  <p>Well.</p>
  
  <p>When we don't need changing <code>vec</code> items, IMO, Examples suggest to use second version (by value). Why they don't suggest something which <code>const</code> references (At least I have not found any direct suggestion):</p>
  
  <pre><code>for (auto const &amp;x : vec) // &lt;-- see const keyword
  {
    // x is a reference to an const item of vec
    // We can not change vec's items by changing x 
  }
  </code></pre>
  
  <p>Isn't it better? Doesn't it avoid a redundant copy in each iteration while it's a <code>const</code>?</p>