CppCon 2023 C++ Memory Model: from C++11 to C++23 -- Alex Dathskovsky

cpp23-dathskovsky.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!

C++ Memory Model: from C++11 to C++23

by Alex Dathskovsky

Summary of the talk:

In the realm of C++ development, threading and memory management play a crucial role in crafting highly parallel and optimized programs. However, the absence of a memory model in C++98 posed challenges. Thankfully, with the advent of C++11, significant changes were introduced, including the introduction of a memory model, which brought forth a plethora of new and exciting tools for developers to leverage. This talk aims to delve into the realm of the C++ memory model, showcasing the arsenal of tools at our disposal. Attendees will gain insights into how CPUs and compilers optimize code and understand the criticality of adhering to the memory model correctly. Practical guidelines on utilizing these tools effectively will also be explored.

Throughout the talk, we will illustrate practical examples and share best practices for utilizing the diverse set of tools now available to us. From atomic operations to memory barriers, we will explore the range of techniques that allow us to develop robust and thread-safe code.

This talk will also illustrate the newer tools from newer C++ standards like JThread and so this talk will show how memory model is used and how it advanced since C++11.

CppCon 2023 Help! My Expression Template Type Names Are Too Long! -- Braden Ganetsky

cpp23-ganetsky.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: Help! My Expression Template Type Names Are Too Long!

by Braden Ganetsky 

Summary of the talk:

Even the name of this talk is too long! If we're ever working with expression templates, we can easily make type names long enough to slow down compilation time. Suddenly our "zero-overhead" expression templates start giving a large compile time overhead. I'll show off a C++20 trick to fix this problem.

Reminder: CppCon 2024 Early Bird ends on Friday

The opening keynote of CppCon 2024 is just 89 days away!

If you're interested in savings, the Early Bird discount for on-line and on-site tickets is available until this Friday, June 21. After that tickets will still be available right up to the conference, but at the full ticket price.

To register for CppCon 2024 with the Early Bird discount, click this link this week.

For details of on-line and on-site tickets, see the Registration page which includes information about student registration discounts, group rates, the CppCon Academy (extra pre- and post-conference classes by world-renowned instructors), the diversity dinner, the "Meet the Presenters" banquet, and much more!

Why Can’t I Find the Injected Name of a Templated Class’s Templated Base Class? -- Raymond Chen

RaymondChen_5in-150x150.jpgSome time ago, I wrote about how injected class names were the C++ feature you didn’t even realize that you were using. Injected class names let you use the plain name for the class being defined without needing to fully qualify it with namespaces and template parameters. Furthermore, injected class names are public and can be inherited.

“But wait, I’m trying to use the injected class name of my base class, but the compiler won’t accept it.”

Why Can’t I Find the Injected Name of a Templated Class’s Templated Base Class?

by Raymond Chen

From the article:

Some time ago, I wrote about how injected class names were the C++ feature you didn’t even realize that you were using. Injected class names let you use the plain name for the class being defined without needing to fully qualify it with namespaces and template parameters. Furthermore, injected class names are public and can be inherited.

“But wait, I’m trying to use the injected class name of my base class, but the compiler won’t accept it.”

template<typename T>
struct Base
{
    Base(T value);
};

template<typename T>
struct Derived : Base<T>
{
    Derived(T value) : Base(value) {}
};

This generates a compiler error.

 

CppCon 2023 Filling the Bucket: Reading Code, C++ Code Interviews & Exams -- Amir Kirsh

cpp23-kirsh.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: Filling the Bucket: Reading Code, C++ Code Interviews & Exams

by Amir Kirsh 

Summary of the talk:

We are going to review and practice a reading code challenge. Reading code skills are quite important, maybe even more than writing code. So let's dive together into filling the bucket code reading challenge!

CppCon 2023 Back to Basics: The Rule of Five in C++ -- Andre Kostur

cpp23-kostur.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!

Back to Basics: The Rule of Five in C++

by Andre Kostur

Summary of the talk:

Designing a class to behave correctly when copied and moved takes a lot of thought. The Core Guidelines provide guidance to streamline that work. In this talk we are going to look at the Core Guideline known as "the Rule of Five", how it came about, and is there anything better.

An Informal Comparison of the Three Major Implementations of std::string -- Raymond Chen

RaymondChen_5in-150x150.jpgWe saw some time ago that the three major implementations of std::string are all quite different...

An informal comparison of the three major implementations of std::string

by Raymond Chen

From the article:

In the original version of this article, I got the sense of the “small/large” bit backward in the clang implementation. This in turn led to redoing the code generation and new code golfing results.

We’ll compare these versions based on the complexity of some commonly-used operations.

C++ Safety with Herb Sutter

The U.S. government released a report calling on the technical community to proactively reduce the attack surface area of software infrastructure. Herb tackles the concerns cast on C++ on memory safety.

C++ Safety with Herb Sutter


by Jordi Mon Companys in Software Engineering Daily

From the interview:

It's really, really important as native languages C and C++, not to have our heads in the sand and say, "Oh, well, we've been hearing this for years. All is well." No, it's not. We have work to do. But it's also important not to go to the other extreme, and think that, "Oh, if we just magically wave a wand and make all the world's software, suddenly convert overnight to memory-safe languages", which would be great if it can be done. It's not technically feasible. ut even if we could do that, we're not going to make most of the attacks go away.

CppCon 2023 Exceptionally Bad: The Misuse of Exceptions in C++ & How to Do Better -- Peter Muldoon

cpp23-muldoon.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!

Exceptionally Bad: The Misuse of Exceptions in C++ & How to Do Better

by Peter Muldoon

Summary of the talk:

Exceptions were originally heralded as a new modern way to handle errors. However the C++ community is split as to whether exceptions are useful or should be banned outright. It has not helped the pro-exception lobby that in their enthusiasm to embrace exceptions, a lot of code has been written that puts exceptions in a bad light.

In this talk, We will present the original intent/history of exceptions and a brief overview of how exception mechanics work and how they circumvent the usual stack return mechanism to set the stage. we will then examine the philosophy of using exceptions and then the many cases of exception misuse including resource management, retries, hierarchies, data passing and control flow to name but a few.

For each case, we will then suggest better ways to handle each specific situation. In many cases, exceptions are often dropped in favor of some other more appropriate paradigm.
Finally, we will introduce situations that can truly benefit from exceptions and what a model exception class might look like.

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

RaymondChen_5in-150x150.jpgLast time, we refined our change counter-based stateful but coalescing update notification. This version still relies on a UI thread to do two things: (1) make the final final change counter check and the subsequent callback atomic, and (2) to serialize the callbacks.

Adding State to the Update Notification Pattern, Part 7

by Raymond Chen

From the article:

If we don’t have a UI thread, then we open a race condition.

 
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);
}