Adding State to the Update Notification Pattern, Part 6 -- Raymond Chen
Last time, we built a stateful but coalescing update notification using a change counter to identify which request is the latest one, but noted that it does unnecessary work. Let’s see if we can avoid the unnecessary work.
Adding State to the Update Notification Pattern, Part 6
by Raymond Chen
From the article:
We could add some early exits to abandon the work if we notice that we are no longer doing work on behalf of the most recent text change. It means that we have to switch the change counter variable to a
std::since we will be reading the variable from the background thread at the same time the UI thread may be modifying it.atomic class EditControl { ⟦ ... existing class members ... ⟧ std::atomic<unsigned> m_latestId; }; winrt::fire_and_forget EditControl::TextChanged(std::string text) { auto lifetime = get_strong(); auto id = m_latestId.fetch_add(1, std::memory_order_relaxed); co_await winrt::resume_background(); if (!IsLatestId(id))) co_return; std::vector<std::string> matches; for (auto&& candidate : FindCandidates(text)) { if (candidate.Verify()) { matches.push_back(candidate.Text()); } if (!IsLatestId(id))) co_return; } co_await winrt::resume_foreground(Dispatcher()); if (!IsLatestId(id))) co_return; SetAutocomplete(matches); } bool EditControl::IsLatestId(unsigned id) { return id == m_latestId.load(std::memory_order_relaxed); }The background worker periodically checks whether its work has been discarded and abandons its efforts if so.

In today's post, I will continue where I left off with last month's post Understanding the role of cv-qualifiers in function parameters. This time, I will focus on type deduction.
The new
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.