Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-67970

QString should support efficient conversion to std::*string_view

    XMLWordPrintable

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

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              cnn Qt Core & Network
              herb.sutter Herb Sutter
              Vladimir Minenko Vladimir Minenko
              Alex Blasche Alex Blasche
              Votes:
              6 Vote for this issue
              Watchers:
              10 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes