title: Moving std::istream
body: <p>I have a <code>Scanner</code> class to tokenize streams of characters coming from files, <code>cin</code>, etc.</p>
  
  <pre><code>class Scanner {
  public:
    Scanner(std::istream&amp;&amp; c) : input{std::move(c)} {}
  
  private:
    std::istream input;
  };
  </code></pre>
  
  <p>This code does not compile because the move constructor of <code>std::istream</code> is protected. I could use a reference to the stream instead, but then, I have no guarantee that someone is not playing with my stream outside of the <code>Scanner</code> class (<code>ss</code> below). </p>
  
  <pre><code>  std::string code = "this is code";
    std::stringstream ss{code};
    Scanner scanner{ss};
  </code></pre>
  
  <p>Is there a neat way to address this issue, or do people just use <code>std::istream&amp;</code> and hope for the best?</p>