title: Why doesn't range-for find my overloads of begin and end for std::istream_iterator?
body: <p>I have code like this</p>
  
  <pre><code>std::ifstream file(filename, std::ios_base::in);
  if(file.good())
  {
      file.imbue(std::locale(std::locale(), new delimeter_tokens()));
      for(auto&amp; entry : std::istream_iterator&lt;std::string&gt;(file))
      {
          std::cout &lt;&lt; entry &lt;&lt; std::endl;    
      }
  }
  file.close();
  </code></pre>
  
  <p>where <code>std::istream_iterator&lt;std::string&gt;</code>'s  <code>begin()</code> and <code>end()</code>
  are defined as follows</p>
  
  <pre><code>template&lt;class T&gt;
  std::istream_iterator&lt;T&gt; begin(std::istream_iterator&lt;T&gt;&amp; stream)
  {
      return stream;
  }
  
  template&lt;class T&gt;
  std::istream_iterator&lt;T&gt; end(std::istream_iterator&lt;T&gt;&amp; stream)
  {
      return std::istream_iterator&lt;T&gt;();
  }
  </code></pre>
  
  <p>which is what <strong>Mark Nelson</strong> has also written about in Dr. Dobb's <a href="http://www.drdobbs.com/cpp/auto-types-and-range-based-for-statement/232900460?pgno=2" rel="nofollow noreferrer">here</a>. Alas, the code fails to compile on my Visual Studio 2012 with error messages</p>
  
  <blockquote>
    <p>error C3312: no callable 'begin' function found for type 'std::istream_iterator&lt;_Ty>'</p>
  </blockquote>
  
  <p>and</p>
  
  <blockquote>
    <p>error C3312: no callable 'end' function found for type 'std::istream_iterator&lt;_Ty>'</p>
  </blockquote>
  
  <p><strong>Question:</strong> Is there something I haven't noticed, bug in the compiler (unlikely, but just in case) or... Well, any ideas?</p>
  
  <p><br/>
  This questions is cleaned up considerably, as advised by <a href="https://stackoverflow.com/users/500104/xeo">Xeo</a>. To provide more background and references this is related to my <a href="https://stackoverflow.com/questions/11269678/how-to-capture-0-2-groups-in-c-regular-expressions-and-print-them">other question</a> on Stackoverflow, I was wondering how to make line based parsing cleaner than the usual loops. A bit of coding and checking from the internet, and I had a working sketch as follows</p>
  
  <pre><code>std::ifstream file(filename, std::ios_base::in);
  if(file.good())
  {               
      file.imbue(std::locale(std::locale(), new delimeter_tokens()));
      for(auto&amp; entry : istream_range&lt;std::string&gt;(file)
      {
          std::cout &lt;&lt; entry &lt;&lt; std::endl;    
      }
  }
  file.close();
  </code></pre>
  
  <p>but there was slight snag I tried to remedy. I think it would look more natural to write as in the code that fails to compile and not like</p>
  
  <pre><code>for(auto&amp; entry : istream_range&lt;std::string&gt;(file)
  </code></pre>
  
  <p>Please, take a note of the different iterator. The <strong>delimeter_tokens</strong> is defined like <a href="https://stackoverflow.com/users/415784/nawaz">Nawaz</a> kindly has shown <a href="https://stackoverflow.com/questions/5607589/right-way-to-split-an-stdstring-into-a-vectorstring">here</a> (code not duplicated) and <strong>istream_range</strong> as in Code Synthesis blog <a href="http://www.codesynthesis.com/~boris/blog/2012/05/16/cxx11-range-based-for-loop/" rel="nofollow noreferrer">here</a>. I think the begin and end implementations should work, as advertised in the aforementioned Code Synthesis blog post<blockquote>The last rule (the fallback to the free-standing begin()and end() functions) allows us to non-invasively adapt an existing container to the range-based for loop interface.</blockquote></p>
  
  <p>Thus my question with all the (ir)relevant background.</p>