C++ Logo

std-proposals

Advanced search

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

From: Hadriel Kaplan <hkaplan_at_[hidden]>
Date: Fri, 13 Oct 2023 10:57:57 +0000
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



Juniper Public

Received on 2023-10-13 10:58:02