title: Reinterpret a narrow (char) input stream as a wide (wchar_t) stream
body: <p>I'm given an <code>std::istream</code> that contains an UTF-16 encoded string. Imagine an UTF-16 encoded text file that has been opened like this:</p>
  <pre><code>std::ifstream file( &quot;mytext_utf16.txt&quot;, std::ios::binary );
  </code></pre>
  <p>I want to pass this stream to a function that takes a <code>std::wistream&amp;</code> parameter. I cannot change the file stream type to std::wifstream.</p>
  <p><strong>Question:</strong> Are there any facilities in the standard or boost libraries that enable me to &quot;reinterpret&quot; the istream as a wistream?</p>
  <p>I'm imagining an adapter class similar to <a href="http://www.cplusplus.com/reference/locale/wbuffer_convert/" rel="nofollow noreferrer">std::wbuffer_convert</a> except that it shouldn't do any encoding conversion. Basically for each wchar_t that is read from the adapter class, it should just read two bytes from the associated istream and <code>reinterpret_cast</code> them to wchar_t.</p>
  <p>I have created an implementation using <a href="http://www.boost.org/doc/libs/release/libs/iostreams/" rel="nofollow noreferrer">boost::iostreams</a> that can be used like this and works like a charm:</p>
  <pre><code>std::ifstream file( &quot;mytext_utf16.txt&quot;, std::ios::binary );
  
  // Create an instance of my adapter class.
  reinterpret_as_wide_stream&lt; std::ifstream &gt; wfile( &amp;file );
  
  // Read a wstring from file, using the adapter.
  std::wstring str;
  std::get_line( wfile, str );    
  </code></pre>
  <p>Why am I asking then? Because I like to reuse existing code instead of reinventing the wheel.</p>