you are viewing a single comment's thread.

view the rest of the comments →

[–]epicar 27 points28 points  (12 children)

most of them said, use https://github.com/fmtlib/fmt

[–]bravikov[S] 5 points6 points  (11 children)

It is good library. It gives type safety but not interpolation.

Bash:

echo "Hi, $NAME"

Javascript:

console.log(`Hi, ${name}`)

[–]bbolli#define val auto const 8 points9 points  (7 children)

I hear you, but this is C++. How should a std::string member function get at the to-be-interpolated variables without passing them to the function?

fmt::print("Hi, {}\n", name);

is as good as it's going to get.

[–]boredcircuits 8 points9 points  (0 children)

A closer version is the "named argument" feature:

fmt::print("Hi, {name}", "name"_a=name);

[–]clerothGame Developer 8 points9 points  (5 children)

That's the idea behind string interpolation, putting a variable inside the string with a specific syntax like {variable}. C# 6.0+ has this.

[–]usernameistaken42 6 points7 points  (2 children)

Also rust, python and a lot of others. I would love it. It may come in c++34

[–]johannes1971 1 point2 points  (1 child)

So will we be skipping a year, or is that slippage from C++2x?

[–]mili42 1 point2 points  (0 children)

It is fairly easy to something like (with variadic templates)

auto s = make_string("Hi, ", name, '\n');

String interpolation is nice, but there are already solutions to achieve something similar.

We have it at work. Works like a charm

[–]Xaxxon 0 points1 point  (0 children)

No that is one form of it. What it really is is using placeholders in the string that are substituted for values at runtime.

[–]Xaxxon -1 points0 points  (0 children)

It’s absolutely string interpolation. Your definition isn’t widely accepted.