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:13:26 +0000
> From: Bengt Gustafsson <bengt.gustafsson_at_[hidden]>

> 2. Not allowing expressions in {} after the colon (what is called nested
> replacement fields). I don't actually see much implementation effort
> reduction in disallowing this (it is allowed in P1819). The code to
> interpret an expression inside a {} is already there and its result, to
> put the expression afterwards is exactly the same.

The reason I didn't want to support it is, as far as I'm aware, anything after the colon delimiter is essentially arbitrary, user-definable syntax - because it's actually defined by the *type* of the argument.

For example I can create a class Foo, and define a std::formatter<Foo> that looks for '{...}' braces in the std::format_parse_context and do whatever I want with them.

The fact that a nested-braces within the format-spec is used for another argument is only true for the standard-provided std::formatter of standard types. It need not be true for user types. (again: as far as I'm aware, anyway)

-hadriel



Juniper Public

Received on 2023-10-16 05:13:34