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

As a user of QStringBuilder, I would like to have a type-erased container of QStringBuilder expressions

    XMLWordPrintable

Details

    • User Story
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • None
    • None

    Description

       There are two use-cases for a type-erased QStringBuilder-expression container:

      1. Build up a larger expression step-by-step
      2. Passing expressions into and out of functions, esp. across ABI boundaries

      Regarding the first point: Within a single function, provided QTBUG-99291 is implemented, I can just use auto variables to store sub-expressions:

      auto x1 = str1 % str2 % c1;
      auto x2 = x1 % str3 % c2 % ~~~~;
      label.setText(x2);
      

      But, and this ties in with the second point, if I want to factor parts of the building into a separate function, I'd need to make it a template, with all the associated disadvantage (executable code bloat, excessive compiler error messages). With a type-erased expression container, I could write a normal function:

      QStringBuilderExpression<QChar> formatLine(QStringBuilderExpression<QChar> header, QStringBuilderExpression<QChar> content) {
          return std::move(header) % u", " % std::move(content) % u"\r\n";
      }
      

      and this function could even be out-of-line.

      This expression container would also be able to support appending:

      // same as first example, except w/o auto variables:
      QStringBuilderExpression x1 = str1 % str2 % c1;
      x1 += str3 % c2 % ~~~:
      label.setText(x1);
      

      With auto variables, this is not possible, because op+= changes the static type of the variable. But because QStringBuilderExpression is type-erased, it can store both the old and the new type in the same object.

      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
              mmutz Marc Mutz
              Vladimir Minenko Vladimir Minenko
              Alex Blasche Alex Blasche
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes