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: Thu, 19 Oct 2023 12:47:01 +0000
Juniper Public
+AD4- From: Marcin Jaczewski +ADw-marcinjaczewski86+AEA-gmail.com+AD4-
+AD4- Date: Thursday, October 19, 2023 at 6:33 AM

+AD4- +AD4- The challenging part is handling macros that resolve to f/x-strings, in such a sequence as:
+AD4- +AD4- X+ACI-a+AD0AIg- COLOR+AF8-RED X+ACIAew-a+AH0AIg- COLOR+AF8-RESET
+AD4- +AD4- I can think of work-arounds, but only if the user invokes a function-like macro for them. For example:
+AD4- +AD4- // using a variadic macro GEN+AF8-XSTRING, created by the programmer
+AD4- +AD4- GEN+AF8-XSTRING(+ACI-a+AD0AIg-, COLOR+AF8-RED, +ACIAew-a+AH0AIg-, COLOR+AF8-RESET)

+AD4- This is close to what I suggest, make string interpolation a build in
+AD4- macro function, then many problems with interpretation will cease to
+AD4- exists:
+AD4- +AGAAYABg-
+AD4- F(+ACI-a+AD0Aew-COLOR+AF8-RED+AH0Aew-a+AH0Aew-COLOR+AF8-RESET+AH0AIg-) // +AD0APg- +ACI-a+AD0AewB9AHsAfQB7AH0AIg-, +ACIAXA-u001b+AFs-31m+ACI-,
+AD4- a, +ACIAXA-u001b+AFs-0m+ACI-

Oh, you're right+ACE- - that's what we should recommend to use:

    std::print(X+ACI-a+AD0Aew-COLOR+AF8-RED+AH0Aew-a+AH0Aew-COLOR+AF8-RESET+AH0AIg-)+ADs-


Maybe we don't need to worry about handling string-literals separated by macros at all then, since they can just be embedded in the format-string, as you pointed out above.

Though I still plan to propose a real preprocessor operator like +AGAAXw-Pragma()+AGA-. And the F+ACIAIg- or X+ACIAIg- will just be preprocessing-tokens that simply get replaced with an invocation of the real operator and the quoted-string portion as a string-literal token. (with simple concatenation handling, etc.)

That way if someone needs to use the operator from within a macro, they can.

-hadriel

Received on 2023-10-19 12:47:28