'C++ inline string interpolation

I found this answer, which is nice, but not enough for me.

They offer

boost::format("error! value was %1% but I expected %2%") % actualValue % expectedValue

Which is nice, but much less readable than what I would like (in some syntax):

boost::format("error! value was %actualValue % but I expected %expectedValue%")

In C# that is

$"error! value was {actualValue} but I expected {expectedValue}"

In Python that is

f"error! value was {actualValue} but I expected {expectedValue}"

Is that supported somehow in C++?



Solution 1:[1]

There is a C++ standard proposal from Microsoft. Interpolated literals

The samples.

int port = 27015;
std::cout << f"Connecting on port {port}...\n";
int get_result() { return 42; }
std::cout << f"The result is {get_result()}\n";

I like this kind of syntax. It's concise and beautiful.

Unfortunately, there is no real C++ implementation libraries until 2022.2.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1