title: Range based for with pair<Iterator,Iterator>
body: <p>I have a question with respect to the following answer: </p>
  
  <p><a href="https://stackoverflow.com/a/15828866/2160256">https://stackoverflow.com/a/15828866/2160256</a></p>
  
  <p>As stated there, we cannot use range based for with BGL like this:</p>
  
  <pre><code>   for(auto e : boost::edges(g))
         // do something with e
  </code></pre>
  
  <p>However, <a href="http://en.cppreference.com/w/cpp/iterator/begin" rel="nofollow noreferrer">here</a> it states, that we can overload the begin() and end() functions that are required to use range based for semantics. So I tried:</p>
  
  <pre><code>   template&lt;class I&gt;
     I begin(std::pair&lt;I,I&gt;&amp; p)
     { return p.first;}
  
     template&lt;class I&gt;
     I end(std::pair&lt;I,I&gt;&amp; p)
     { return p.second;}
  </code></pre>
  
  <p>However, the compiler still complains:</p>
  
  <blockquote>
    <p>error: no matching function for call to
    ‘<code>begin(std::pair&lt;some_really_ugly_type,some_really_ugly_type&gt;&amp;)</code>’</p>
  </blockquote>
  
  <p>What am I doing wrong? Does the name lookup not work? Or is this not possible after all?
  I also found <a href="https://stackoverflow.com/questions/6167598/why-was-pair-range-access-removed-from-c11">this answer</a>, which works, but shouldtn't it be possible with the begin/end free function overlods as well?
  Regards, Marti</p>
  
  <p>BTW: I find it really tiresome to write</p>
  
  <pre><code>   typename Graph::edge_iterator ebegin, eend;
     std::tie(ebegin,eend) = boost::edges(_graph);
     std::for_each(ebegin,eend,[&amp;](const edge_descriptor&amp; e){/*do something with e*/;});
  </code></pre>
  
  <p>UPDATE: C++17 should now allow the following :-)</p>
  
  <pre><code>auto [ebegin,eend] = boost::edges(_graph);
  </code></pre>