title: Why does `std::basic_ifstream<char16_t>` not work in c++11?
body: <p>The following code works as expected. The source code, file "file.txt" and "out.txt" are all encoded with utf8. But it does not work when I change <code>wchar_t</code> to <code>char16_t</code> at the first line in <code>main()</code>. I've tried both gcc5.4 and clang8.0 with <code>-std=c++11</code>. My goal is to replace <code>wchar_t</code> with <code>char16_t</code>, as <code>wchar_t</code> takes twice space in RAM. I thought these 2 types are equally well supported in c++11 and later standards. What do I miss here?</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;fstream&gt;
  #include&lt;locale&gt;
  #include&lt;codecvt&gt;
  #include&lt;string&gt;
  
  int main(){
    typedef wchar_t my_char;
  
    std::locale::global(std::locale("en_US.UTF-8"));
  
    std::ofstream out("file.txt");
    out &lt;&lt; "123正则表达式abc" &lt;&lt; std::endl;
    out.close();
  
    std::basic_ifstream&lt;my_char&gt; win("file.txt");
    std::basic_string&lt;my_char&gt; wstr;
    win &gt;&gt; wstr;
    win.close();
  
    std::ifstream in("file.txt");
    std::string str;
    in &gt;&gt; str;
    in.close();
  
    std::wstring_convert&lt;std::codecvt_utf8&lt;my_char&gt;, my_char&gt; my_char_conv;
    std::basic_string&lt;my_char&gt; conv = my_char_conv.from_bytes(str);
  
    std::cout &lt;&lt; (wstr == conv ? "true" : "false") &lt;&lt; std::endl;
  
    std::basic_ofstream&lt;my_char&gt; wout("out.txt");
    wout &lt;&lt; wstr &lt;&lt; std::endl &lt;&lt; conv &lt;&lt; std::endl;
    wout.close();
  
    return 0;
  }
  </code></pre>
  
  <hr>
  
  <h2>EDIT</h2>
  
  <p>The modified code does not compile with clang8.0. It compiles with gcc5.4 but crashes at run-time as shown by @Brian.</p>