title: Can I specialize std::begin and std::end for the return value of equal_range()?
body: <p>The <code>&lt;algorithm&gt;</code> header provides <code>std::equal_range()</code>, as well as some containers having it as a member function. What bothers me with this function is that it returns a pair of iterators, making it tedious to iterate from the begin iterator to the end iterator. I'd like to be able to use <code>std::begin()</code> and <code>std::end()</code> so that I can use the C++11 range-based for-loop.</p>
  
  <p>Now, I've heard contradictory information in regards to specializing <code>std::begin()</code> and <code>std::end()</code> - I've been told that adding anything to the std namespace results in undefined behavior, whereas I have also been told that you can provide your own specializations of <code>std::begin()</code> and <code>std::end()</code>.</p>
  
  <p>This is what I am doing right now:</p>
  
  
  
  <pre><code>namespace std
  {
      template&lt;typename Iter, typename = typename iterator_traits&lt;Iter&gt;::iterator_category&gt;
      Iter begin(pair&lt;Iter, Iter&gt; const &amp;p)
      {
          return p.first;
      }
      template&lt;typename Iter, typename = typename iterator_traits&lt;Iter&gt;::iterator_category&gt;
      Iter end(pair&lt;Iter, Iter&gt; const &amp;p)
      {
          return p.second;
      }
  }
  </code></pre>
  
  <p>And this does work: <a href="http://ideone.com/wHVfkh">http://ideone.com/wHVfkh</a></p>
  
  <p>But I am wondering, what are the downsides to doing this? Is there a better way to do this?</p>