Details
-
Suggestion
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
None
-
None
Description
ISO C++17 has *string_view, intended to be the lingua franca type to let us write non-template functions like f(wstring_view) and pass the contents of any string type containing characters of the given type (wchar_t for wstring_view, char16_t for u16string_view).
A problem is that QString stores QChar, not wchar_t. The closest (but still incorrect) match would be to declare the function f(u16string_view) and then given a QString s we could try to use f({s.utf16(), s.size()}); - except that doesn't work because .utf16() currently returns an unsigned short*, not a char16*. It seems there is no way to do it without using a reinterpret_cast and undefined behavior today, so it would be nice to have a way.
String types like QString are encouraged to provide implicit or explicit conversions to such a view - and without performing an allocation of course.
The ideal solution, if possible, would be to provide an implicit (not 'explicit') "operator wstring_view()" since string_view and wstring_view will likely be the most common ones, for wide and narrow characters respectively.
As requested, highlighting the following: Thiago Macieira, Marc Mutz, Lars Knoll, Simon Hausmann, Ville Voutilainen
Attachments
Issue Links
- relates to
-
QTBUG-70347 QString::operator== for std::*string_view
-
- Open
-