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 08:02:45 +0000
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- Now side tangent, as this could be a preprocessor function, what benefits
+AD4- will it bring to basic C or even using C api in C+-+-?

Good question. I was not proposing nor expecting this change to be adopted by WG14 anytime soon, if ever.

I know there's a preference to keep the two preprocessors the same, at least over time. And there's nothing in the proposed changes that could not also be implemented in the C-preprocessor, obviously.

So yeah, we should think about what that would be useful for and how.


+AD4- C +AGA-printf+AGA- will not switch from +AGAAJQBg- to +AGAAewB9AGA-.
+AD4- This brings me to the conclusion that +AGAAXw-X+AGA- should not be a +ACI-basic+ACI- operation
+AD4- but a composition of lower level macro functions.

Or it could lead to different conclusion: WG14 could define a new printfmt() function, similar to printf() but for which the format-string is that of std::print() et al.

I'd argue that would be less confusing for programmers, faster for preprocessing stage, and less error-prone than trying to convert formats using macros.


+AD4- This could be used with iosteams:
+AD4- +ACM-define FORMAT(A) +ADwAPA- (A) +ADwAPA-
+AD4- +ACM-define ARG(A)
+AD4- +ACM-define BETTER+AF8-OUT(F) +AF8-PARSE+AF8-EXTRACT(F, FORMAT, ARG)

+AD4- //usage
+AD4- int i+ADs-
+AD4- float j+ADs-
+AD4- std::cout +ADwAPA- BETTER+AF8-OUT(+ACIAew-i+AH0Aew-j+AH0AIg-)+ADs-

+AD4- //expand to
+AD4- std::cout +ADwAPA- +ACIAIg- +ADwAPA- (i) +ADwAPA- +ACIAIg- +ADwAPA- (j) +ADwAPA- +ACIAIgA7-


But how is that better than just one of these?:

    std::cout +ADwAPA- F+ACIAew-i+AH0Aew-j+AH0AIgA7-
    std::print(X+ACIAew-i+AH0Aew-j+AH0AIg-)+ADs-

-hadriel

Received on 2023-10-20 08:02:50