This is about the well-known https://fmt.dev/latest/index.html.
On the one hand, fmt::format("Mom {} and Dad {}", "Alice", "Bob")
is expressive, and on the other hand, fmt::format_to
also exists, e.g.
auto out = fmt::memory_buffer();
fmt::format_to(std::back_inserter(out),
"Mom {} and Dad.", "Alice", "Bob");
auto data = out.data(); // pointer to the formatted data
auto size = out.size(); // size of the formatted data
as adapted from the docs https://fmt.dev/latest/index.html.
Now, which one is more efficient? Does the first version -- fmt::format()
-- cause unnecessary string concatenations? To my taste, the first version wins hands-down in terms of expressiveness.