C++ Logo

std-proposals

Advanced search

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

From: Marcin Jaczewski <marcinjaczewski86_at_[hidden]>
Date: Fri, 13 Oct 2023 13:18:02 +0200
pt., 13 paź 2023 o 12:58 Hadriel Kaplan via Std-Proposals
<std-proposals_at_[hidden]> napisał(a):
>
> Back in 2019, https://wg21.link/p1819r0 was submitted for "interpolated literals". I believe it was reviewed in EWG-Incubator back then, and again in 2022. There appears to have been consensus for the author to keep working on it generally, but no consensus on the proposal's specific details.
>
> I'd like to propose a different solution - but only for the specific idea of having f-strings in C++, as opposed to a general string-interpolation framework.
>
> I've written up a brief strawman here: https://tinyurl.com/3tr8rv22
>
> The basic idea is to just syntactically replace an f-string with its std::format() counterpart, as a new step between phase 6 and 7 of translation, right after concatenation of string-literals. I.e., an f-string would just be syntactic-sugar for std::format().
>
> More-detailed rules are written in the linked proposal above. It even includes a way to add a customization point should that be desired by the WG, at which point it's a form of interpolation and could perhaps fully replace P1819.
>
> It's arguably a bit hacky, but it should be far simpler than P1819 to implement, use, and maybe even standardize.
>
> I'm looking for feedback on whether this is an idea worth pursuing, or whether it's a horrible idea and I should never raise it again.
>
> -hadriel
>

I do not think it is a good idea to hardcoding `std::foramt` to this
functionality. And the way to out-out it is even worse.

We have already tool to handle custom string using User-defined literals:
```
std::string operator ""_w(const char16_t*, size_t);
```

Then `F"{aa}"_w` will simply transformed to:

```
operator ""_w("{0}", strlen("{0}"), aa); //always use (ptr, size)
first to prevent confusion
```




:

>
>
> Juniper Public
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2023-10-13 11:18:15