C++26: std::format improvement (Part 1) -- Sandor Dargo
C++26 brings a series of improvements to
std::format, continuing the work started in C++20 and refined in C++23. These changes improve formatting consistency, runtime safety, and user ergonomics. There are so many of these updates, that I decided to divide them into two articles.
C++26: std::format improvement (Part 1)
by Sandor Dargo
From the article:
Arithmetic overloads of
std::to_stringandstd::to_wstringusestd::formatP2587R3 by Victor Zverovich proposes replacing
sprintfwithstd::formatin the arithmetic overloads ofstd::to_stringandstd::to_wstring.The motivation?
std::to_stringhas long been known to produce not-so-great and misleading results (differing fromiostreams), especially with floating-point values.std::to_stringuses the global C locale. In practice, it’s unlocalized. Also, it often places the decimal points to suboptimal places:std::cout << std::to_string(-1e-7); // prints: -0.000000 std::cout << std::to_string(0.42); // prints: 0.420000These outputs are imprecise and often unnecessary. By leveragingstd::format(and ultimatelystd::to_chars), we now get clearer, shorter representations. The representations of floating-point overloads become also unlocalized and use the shortest decimal representations.As a result, the above outputs would change as follow:
std::cout << std::to_string(-1e-7); // prints: -1e-7
std::cout << std::to_string(0.42); // prints: 0.42


Release 1.89 of the Boost C++ Libraries is now available.
Another year, another trip report from C++ On Sea!
When should a destructor be virtual in C++? In this post, we’ll explore a real-world example from smart pointer implementation to illustrate when virtual destructors are necessary — and when they’re not.
C++26 is bringing a long-awaited feature to the language: compile-time reflection, enabling programs to introspect and manipulate their own structure during compilation. This powerful capability opens the door to eliminating boilerplate, improving performance, and writing more expressive, reusable code with ease.
Constexpr has been around for a while now, but many don’t fully understand its subtleties. Andreas Fertig explores its use and when a constexpr expression might not be evaluated at compile time.