May 2024

CppCon 2023 Interfaces in C++ -- Megh Parikh

Parikh_-_CppCon_2023.pngRegistration is now open for CppCon 2024! The conference starts on September 15 and will be held in person in Aurora, CO. To whet your appetite for this year’s conference, we’re posting videos of some of the top-rated talks from last year's conference. Here’s another CppCon talk video we hope you will enjoy – and why not register today for CppCon 2024!

Lightning Talk: Interfaces in C++ - Megh Parikh - CppCon 2023

by Megh Parikh

Summary of the talk:

I explain some of the ways to make interfaces, both static and dynamic in this talk, and how concepts can be optionally used.

Adding State to the Update Notification Pattern, Part 2 -- Raymond Chen

RaymondChen_5in-150x150.jpg

In the realm of asynchronous programming, managing stateful update notifications presents a daunting challenge. In our ongoing exploration, we scrutinize a solution that aims to address this challenge by seamlessly handling multiple requests for work while ensuring that only the last one triggers a notification. However, beneath the surface of this endeavor lies a tangle of legal intricacies and logical pitfalls, urging us to dissect, refine, and ultimately fortify our approach.

Adding State to the Update Notification Pattern, Part 2

by Raymond Chen

From the article:

Last time, we started looking at solving the problem of a stateful but coalescing update notification, where multiple requests for work can arrive, and your only requirement is that you send a notification for the last one. Any time a new request for work arrives, it replaces the existing one.

One attempt to fix this is to check if the work is already in progress, and if so, then hand off the new query to the existing worker. We are using winrt::fire_and_forget, which fails fast on any unhandled exception. This saves us from having to worry about recovering from exceptions. (At least for now.)

User-Defined Formatting in std::format -- Spencer Collyer

logo.pngstd::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 formatformat_toformat_to_n, and formatted_size functions. They no longer take a std::string_view as the format string, but instead a std::format_string (or, for the wide-character overloads std::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 with make_format_args or make_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 parse function of the formatter classes described in this article.