Details
-
User Story
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
None
-
None
Description
There are two use-cases for a type-erased QStringBuilder-expression container:
- Build up a larger expression step-by-step
- 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
- is cloned by
-
QTBUG-99301 As a user of QStringBuilder, I would like to be able to express repetition and conditionals in expressions
- Open