title: Why use non-member begin and end functions in C++11?
body: <p>Every standard container has a <code>begin</code> and <code>end</code> method for returning iterators for that container. However, C++11 has apparently introduced free functions called <a href="http://en.cppreference.com/w/cpp/iterator/begin" rel="noreferrer"><code>std::begin</code></a> and <a href="http://en.cppreference.com/w/cpp/iterator/end" rel="noreferrer"><code>std::end</code></a> which call the <code>begin</code> and <code>end</code> member functions. So, instead of writing</p>
  
  <pre><code>auto i = v.begin();
  auto e = v.end();
  </code></pre>
  
  <p>you'd write</p>
  
  <pre><code>auto i = std::begin(v);
  auto e = std::end(v);
  </code></pre>
  
  <p>In his talk, <a href="http://channel9.msdn.com/Events/BUILD/BUILD2011/TOOL-835T" rel="noreferrer">Writing Modern C++</a>, Herb Sutter says that you should always use the free functions now when you want the begin or end iterator for a container. However, he does not go into detail as to <em>why</em> you would want to. Looking at the code, it saves you all of one character. So, as far as the standard containers go, the free functions seem to be completely useless. Herb Sutter indicated that there were benefits for non-standard containers, but again, he didn't go into detail.</p>
  
  <p>So, the question is what exactly do the free function versions of <code>std::begin</code> and <code>std::end</code> do beyond calling their corresponding member function versions, and why would you want to use them?</p>