C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Supporting f-strings in C++: draft-R1

From: Hadriel Kaplan <hkaplan_at_[hidden]>
Date: Sun, 15 Oct 2023 16:45:34 +0000
> From: Std-Proposals <std-proposals-bounces_at_[hidden].org> on behalf of Sebastian Wittmeier via Std-Proposals <std-proposals_at_lists.isocpp.org>

> you write that there is no preprocessor support within the f-strings.
> Is it possible to concatenate preprocessor macro results with preprocessor string concatenation?
> If yes, would it be further possible to have the preprocessor preprocess code in its usual way, put it through a STRINGIFY macro and concatenate it into the f string?

You can use preprocessor macros to stringify other macro expansions as you can do today, of course - but as far as I know the preprocessor cannot concatenate two string literals into one token literal using the `##`. It's usually the phase-6 translation right afterwards that concatenates them instead.

So then I don't see how you'd get it to become an f-string, since presumably you'd want to join multiple stringified literals into one final f-string.

For just _one_ stringified macro I think you can do it, but that doesn't seem useful.

I.e., you might be able to get a stringified `__LINE__` for line 42 to become a `F"42"`, but if you wanted it to become `F"{42:x}"` instead, I don't think that's possible. (though I'm no PP expert)

I mean basically think of the `F"..."` or `X"..."` as being similar to `R"(...)"` in terms of tokens, and you can try to create an `R"(...)"` using the preprocessor today to see if it's possible - I don't think it is, but I might be wrong. If it _is_ possible then it should be possible to do for f-strings too.

---

Or maybe I misunderstand you - are you instead saying: "I know macro-magic won't work with f-strings as defined, but can the proposal define some way for it to work?"

-hadriel



Juniper Public

Received on 2023-10-15 16:45:40