C++ Logo

std-proposals

Advanced search

Re: +AFs-std-proposals+AF0 Supporting f-strings in C+-+-: draft-R1

From: Hadriel Kaplan <hkaplan_at_[hidden]>
Date: Fri, 20 Oct 2023 07:32:41 +0000
+AFs- splitting the response up into separate emails +AF0-



Juniper Public
+AD4- From: Marcin Jaczewski +ADw-marcinjaczewski86+AEA-gmail.com +ADw-mailto:marcinjaczewski86+AEA-gmail.com+AD4APg-
+AD4- Date: Thursday, October 19, 2023 at 8:28 PM

+AD4- +AD4- It might be more correct to say f and x are more like this, logically speaking:
+AD4- +AD4-
+AD4- +AD4- +ACM-define +AF8-X(...) +AF8-Xstring( +AF8-Concat(+AF8AXw-VA+AF8-ARGS+AF8AXw-) )
+AD4- +AD4- +ACM-define +AF8-F(...) ::std::format( +AF8-X(+AF8AXw-VA+AF8-ARGS+AF8AXw-) )
+AD4- +AD4-
+AD4- +AD4- And the preprocessor builds the varargs when it sees an F+ACIAIg- or X+ACIAIg- and peeks ahead, as described earlier+ADs- and wraps the one-or-more literals as the args for +AF8-F() or +AF8-X() as appropriate.

+AD4- Do you mean that +AGAAXw-X+AGA- should accept code like:
+AD4- +AF8-X(+ACI-aaaaa+ACI-, +ACI-bbbbbbb+ACI-, +ACI-cccccc+ACI-)

Yes, although technically for that macro it would be getting X+ACIAIg- literals:

    +AF8-X( X+ACI-aaaaa+ACI-, X+ACI-bbbbbbb+ACI-, X+ACI-cccccc+ACI- )


+AD4- I do not think this is needed, normal string get concat any way in next stage
+AD4- and if +AGAAXw-X+AGA- get +ACI-one+ACI- argument that have multiple string parts, it can
+AD4- merge them itself.

I'm not proposing the +AF8-Concat() builtin for the +ACo-purpose+ACo- of general use, I was only noting that it can be used generally too.

For example, today you cannot invoke +AF8-Pragma() with separate string literals - only one.

So you cannot do this today:

+ACM-define DIAGNOSTICS+AF8-IGNORE(TYPE, STATEMENT) +AFw-
    +AF8-Pragma(+ACI-GCC diagnostic push+ACI-) +AFw-
        +AF8-Pragma(+ACI-GCC diagnostic ignored +AFwAIg--W+ACI- STR(TYPE) +ACIAXAAiACI-) +AFw-
        STATEMENT +AFw-
    +AF8-Pragma(+ACI-GCC diagnostic pop+ACI-)


But with +AF8-Concat() you could:

+ACM-define DIAGNOSTICS+AF8-IGNORE(TYPE, STATEMENT) +AFw-
    +AF8-Pragma(+ACI-GCC diagnostic push+ACI-) +AFw-
        +AF8-Pragma( +AF8-Concat( +ACI-GCC diagnostic ignored +AFwAIg--W+ACI-, STR(TYPE), +ACIAXAAiACI- ) ) +AFw-
        STATEMENT +AFw-
    +AF8-Pragma(+ACI-GCC diagnostic pop+ACI-)


Is it useful for anything else? I have no idea. Perhaps the above use-case is the only one it would be useful for, other than f/x-strings.

The only other thing I can think of is that it lets you build a string literal of a specific encoding type (raw, wide, etc.) with smaller pieces that are just narrow/plain string-literals.

For example today you cannot create a raw-string string-literal from smaller macro-expanded literals.

But I don't know if it causes any problems at all for anyone today, though, because obviously string-literals are concatenated in phase-6, and a raw-string can be joined with other types at that time.

-hadriel

Received on 2023-10-20 07:32:56