title: C++: std::istream check for EOF without reading / consuming tokens / using operator>>
body: <p>I would like to test if a <code>std::istream</code> has reached the end without reading from it.</p>
  
  <p>I know that I can check for EOF like this:</p>
  
  <pre><code>if (is &gt;&gt; something) 
  </code></pre>
  
  <p>but this has a series of problems. Imagine there are many, possibly virtual, methods/functions which expect <code>std::istream&amp;</code> passed as an argument.
  This would mean I have to do the "housework" of checking for EOF in each of them, possibly with different type of <code>something</code> variable, or create some weird wrapper which would handle the scenario of calling the input methods.</p>
  
  <p>All I need to do is:</p>
  
  <pre><code>if (!IsEof(is)) Input(is);
  </code></pre>
  
  <p>the method <code>IsEof</code> should guarantee that the stream is not changed for reading, so that the above line is equivalent to:</p>
  
  <pre><code>Input(is)
  </code></pre>
  
  <p>as regards the data read in the <code>Input</code> method.</p>
  
  <p>If there is no generic solution which would word for and <code>std::istream</code>, is there any way to do this for <code>std::ifstream</code> or <code>cin</code>?</p>
  
  <p><strong>EDIT:</strong>
  In other words, the following <code>assert</code> should always pass:</p>
  
  <pre><code>while (!IsEof(is)) {
    int something;
    assert(is &gt;&gt; something);
  }
  </code></pre>