User-Defined Formatting in std::format -- Spencer Collyer
std::format allows us to format values quickly and safely. Spencer Collyer demonstrates how to provide formatting for a simple user-defined class.
User-Defined Formatting in std::format
by Spencer Collyer
From the article:
Since my previous article was first published, based on the draft C++20 standard, the paper [P2216] was published which changes the interface of the
format,format_to,format_to_n, andformatted_sizefunctions. They no longer take astd::string_viewas the format string, but instead astd::format_string(or, for the wide-character overloadsstd::wformat_string). This forces the format string to be a constant at compile time. This has the major advantage that compile time checks can be carried out to ensure it is valid.The interfaces of the equivalent functions prefixed with
v(e.g.vformat) has not changed and they can still take runtime-defined format specs.One effect of this is that if you need to determine the format spec at runtime then you have to use the
v-prefixed functions and pass the arguments as an argument pack created withmake_format_argsormake_wformat_args. This will impact you if, for instance, you want to make your program available in multiple languages, where you would read the format spec from some kind of localization database.Another effect is on error reporting in the functions that parse the format spec. We will deal with this when describing the
parsefunction of theformatterclasses described in this article.

In software development, handling notifications efficiently is pivotal, particularly in user interface scenarios. While traditional notification patterns inform handlers of changes, they often lack crucial state information. In this article, we explore the intricacies of managing stateful updates within the context of C++/WinRT, addressing challenges such as race conditions and ensuring that notification handlers operate on the most recent data for optimal user experience.
In this episode, you learn how default parameters work and why you shouldn't put them on virtual member functions.
The last episode of the series about SObjectizer and message passing:
The safety of C++ has become a hot topic recently. Herb Sutter discusses the language’s current problems and potential solutions.
A new episode of the series about SObjectizer and message passing: