Adding State to the Update Notification Pattern, Part 5 -- Raymond Chen
Managing stateful notifications is challenging when multiple requests arrive, and the goal is to only notify about the latest one. In the EditControl class, we use a counter to track the most recent request, updating it on the UI thread to ensure accurate ordering and prevent stale data from being processed. This approach works but is inefficient due to redundant calculations. Next time, we'll refine this strategy for greater efficiency.
Adding State to the Update Notification Pattern, Part 5
by Raymond Chen
From the article:
We’ve been looking at 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.
This time, we’ll apply the trick of using a counter to record who is doing the work on behalf of the most recent change. Here’s our first attempt:
class EditControl { ⟦ ... existing class members ... ⟧ unsigned m_latestId; }; winrt::fire_and_forget EditControl::TextChanged(std::string text) { auto lifetime = get_strong(); co_await winrt::resume_background(); auto id = ++m_latestId; std::vector<std::string> matches; for (auto&& candidate : FindCandidates(text)) { if (candidate.Verify()) { matches.push_back(candidate.Text()); } } co_await winrt::resume_foreground(Dispatcher()); if (id != m_latestId) co_return; SetAutocomplete(matches); }

You have probably written a class that prints a message in all its special member functions. And like me, you probably wrote it multiple times. I decided to write it well once and for all, and share it.
If you're writing C++, there's a good reason (maybe...) as to why you are. And probably, that reason is performance. So often when reading about the language you'll find all sorts of "performance tips and tricks" or "do this instead because it's more efficient". Sometimes you get a good explanation as to why you should. But more often than not, you won't find any hard numbers to back up that claim. I recently found a peculiar one, the
Another meeting, another slew of potential changes to standard C++. In this recap, I’ll summarize the working draft’s most significant changes, spotlight my favorite proposal at the meeting, Member customization points for Senders and Receivers, and discuss a handful of notable developments.
std::format allows us to format values quickly and safely. Spencer Collyer demonstrates how to provide formatting for a simple user-defined class.