If I'm developing for Windows and some WinAPI functions require me to use LPWSTR as string data type. Is it okay to use C++11's u16string in my library? Are those two data types the same thing?
It looks more like LPWSTR is wchar_t, but nobody likes wchar_t anymore...
The C++11 char16_t type is distinct from wchar_t. In theory you could reinterpret_cast your way between char16_t* and Windows’ wchar_t* (Windows’ wchar_t is 16 bits). In practice, however, Visual C++ 10.0 – and I think also Visual C++ 11.0 – lacks support for Unicode literals like u'A' or u"A".
Summing up (I’ve found that on SO one should better make all conclusions explicit):
“Is it okay to use C++11's u16string in my library?”
Certainly, but not as direct plug-in replacements for wchar_t strings, and as of 2012 currently problematic (due to lack of support for literals) if you plan on supporting Visual C++.
“Are those two data types the same thing?”
No.
“nobody likes wchar_t anymore...”
That’s certainly not the case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With