C++ Logo

std-proposals

Advanced search

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

From: Hadriel Kaplan <hkaplan_at_[hidden]>
Date: Mon, 16 Oct 2023 05:11:31 +0000
Hi Bengt,
I'll split up the response into separate emails...

> From: Bengt Gustafsson <bengt.gustafsson_at_[hidden]ys.com>

> 1. The problem with the colon in the ternary ? operator. I don't think
> it is much more complicated to handle this than to count matching
> parentheses. The extra implementation to find the ? and then pass over
> the next : on the outer level should be rather easy to do.

Unfortunately ternaries are not the only problem. I just showed a ternary because I thought it would be the most-common case of syntax ambiguity.

But there are at least two other problems:

1. C++ may add other use-cases for single colons or question-marks in the future, that would affect this parsing. For example P2561, or the '?:' "Elvis" operator that some compilers even support today.

2. If we only trivially-scan the replacement-field for the colon delimiter, then even a colon appearing within an internal string literal would cause a problem:

    F"has key = { map.contains(\"a:b\") }";

At least, assuming we don’t require the scanning to have to keep track of and ignore string literals when looking for a delimiter.

---

And I say "at least two problems" because it's assuming I haven't missed some other valid scenario for a single-colon to appear in an expression. :)

-hadriel



Juniper Public

Received on 2023-10-16 05:11:46