C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Type-safe printf and auto

From: Robin Rowe <robin.rowe_at_[hidden]>
Date: Sun, 12 Mar 2023 11:25:43 -0700
> Have you looked at std::format? It's part of C++20.

Thiago, you make a good point, e.g.:

std::string message = std::format("The answer is {}.", 42);

https://en.cppreference.com/w/cpp/utility/format

There's also std::print in C++23.

https://en.cppreference.com/w/cpp/io/print

A couple issues:

1. Not practical to rewrite legacy C/C++ code containing a zillion
printf statements.

2. Building embedded systems and game servers, we may want to avoid
std::string due to heap global lock.

It's not that we lack more modern approaches for type-safe printing such
as std::iostream, std::format or std::print. It's that a small change to
printf could make legacy code maintenance and embedded systems
development better.

Appreciate all feedback...

Robin

Received on 2023-03-12 18:25:47