Is it specified what will happen if I imbue basic_stream<char> with locale with codecvt_utf16<char> facet?
Basically, I use typedef wchar_t tchar; and typedef char tchar; to alter interfaces for (what I call) Unicode and non-Unicode builds of my library. I want to make the source simpler by always imbuing my file streams with locale with codecvt_utf16<tchar> facet. Will this work anyhow at all?
(I would not mind if the file read by such imbued fstream would have to contain either only ASCII or only code points representable in current global locale.)
EDIT:
Given that codecvt_utf16<char> seems to be unspecified behaviour, what about imbuing basic_stream with codecvt_utf16<wchar_t>? Is this behaviour specified?
Per C++0x,
codecvt_utf*<>can be instantiated with wide characters only. What happens if you usecharis not specified, the only way to know is to try.Bear in mind that codecvt_utf16 converts to/from external UTF-16 representation. That is, your file is supposed to be encoded in UTF-16. You might want to consider using UTF-8 instead.
As a side note, it is a mystery to me why would anyone want anything non-Unicode these days. Do people enjoy using restricted character sets or what?