title: Should I use std::for_each?
body: <p>I'm always trying to learn more about the languages I use (different styles, frameworks, patterns, etc). I've noticed that I never use <a href="http://en.cppreference.com/w/cpp/algorithm/for_each" rel="noreferrer"><code>std::for_each</code></a> so I thought that perhaps I should start. The goal in such cases is to expand my mind and <strong>not</strong> to improve the code in some measure (readability, expressiveness, compactness, etc).</p>
  
  <p>So with that context in mind, is a good idea to use <code>std::for_each</code> for simple tasks like, say, printing out a vector:</p>
  
  <pre><code>for_each(v.begin(), v.end(), [](int n) { cout &lt;&lt; n &lt;&lt; endl; }
  </code></pre>
  
  <p>(The <code>[](int n)</code> being a lambda function). Instead of:</p>
  
  <pre><code>for(int i=0; i&lt;v.size(); i++) { cout &lt;&lt; v[i] &lt;&lt; endl; }
  </code></pre>
  
  <p>I hope this question doesn't seem pointless. I guess it almost asks a larger question... should an intermediate programmer use a language feature even though he doesn't really need to at <strong>this time</strong> but just so that he can understand the feature better for a time that may actually greatly benefit from it. Although this larger question has probably already been asked (e.g. <a href="https://stackoverflow.com/questions/4764325/c-standard-library-when-should-i-use-it-and-when-shouldnt-i">here</a>).</p>