title: Preferred standard use: range based for or std::for_each
body: <p>In <a href="http://en.wikipedia.org/wiki/C%2B%2B11" rel="noreferrer">C++11</a>, there are two loops over all elements (range based for and for_each). Is there any reason to prefer one over the other or are there situations where one is a better fit?</p>
  
  <pre><code>for (auto&amp; elem: container) {
    // do something with elem
  }
  
  std::for_each(container.begin(), container.end(),
                [](Elem&amp; elem) {
                  // do something with elem
                });
  </code></pre>
  
  <p>My idea would be that the first is simpler and is similar to range based loops in other languages while the second also works for sequences that are not complete containers and the second is more similar to other <code>std</code>-algorithms.</p>