News

CppCon 2022 find-move-candidates in Cpp -- Chris Cotter

cppcon-2022-find-move-candidates-in-cpp-chris-cotter.pngRegistration is now open for CppCon 2023! The conference starts on October 1 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 2023!

Lightning Talk: find-move-candidates in C++

by Chris Cotter

Summary of the talk:
A clang tool to automatically find code that should use std::move to reduce unnecessary copies.

Bitwise Binary Search: Elegant and Fast -- Orson Peters

peters-bitwisebinarysearch.png

I recently read the article Beautiful Branchless Binary Search by Malte Skarupke. In it they discuss the merits of the following snippet of C++ code implementing a binary search.

Bitwise Binary Search: Elegant and Fast

by Orson Peters

From the article:

In this article I will provide an alternative implementation based on similar ideas but with a very different interpretation that is (in my opinion) incredibly elegant and clear to understand, at least as far as binary searches go. The resulting implementation also saves a comparison in almost every case and ends up quite a bit smaller.

Dealing with Sharing -- Rainer Grimm

temp_file_DealingwithSharing-Grimm1.pngIf you don’t share, no data races can happen. Not sharing means that your thread works on local variables. This can be achieved by copying the value, using thread-specific storage, or transferring the result of a thread to its associated future via a protected data channel.

Dealing with Sharing

by Rainer Grimm

From the article:

The patterns in this section are quite obvious, but I will present them with a short explanation for completeness. Let me start with Copied Value. If a thread gets its arguments by copy and not by reference, there is no need to synchronize access to any data. No data races and no lifetime issues are possible.

Data Races with References

The following program creates three threads. One thread gets its argument by copy, the other by reference, and the last by...

CppCon 2022 Finding the Average of 2 Integers -- Tomer Vromen

cppcon-2022-finding-the-average-of-2-integers-tomer-vromen.pngRegistration is now open for CppCon 2023! The conference starts on October 1 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 2023!

Lightning Talk: Finding the Average of 2 Integers

by Tomer Vromen

Summary of the talk:

I'm going to discuss the (a+b)/2 problem - not the midpoint problem (for which Marshal is an expert) but rather the one with a possibly fractional result. It will be a quick taste of the limits of using floating points to represent integers.

Concurrency Patterns -- Rainer Grimm

There are many well-established patterns used in the concurrency domain. They deal with synchronization challenges such as sharing and mutation but also with concurrent architectures. Today, I will introduce and dive deeper into them in additional posts.

Concurrency Patterns

by Rainer Grimm

From the article:

The main concern when you deal with concurrency is shared, mutable state or, as Tony Van Eerd put it in his CppCon 2014 talk “Lock-free by Example”: “Forget what you learned in Kindergarten (ie stop Sharing)”. A crucial term for concurrency is a data race. Let me first define this term.

  • Data race: A data race is when at least two threads access a shared variable simultaneously. At least one thread tries to modify the variable. If your program has a data race, it has undefined behavior. This means all outcomes are possible, so reasoning about the program makes no sense anymore.

A necessary condition for a data race is a mutable, shared...

Mutating Through a Filter -- Barry Revzin

MutatingThroughaFilter.pngNico Josuttis gave a talk recently that included an example and I wanted to explain what’s going on in this example, what the issue is, and what (if anything) is broken.

Mutating Through a Filter

by Barry Revzin

From the article:

As with a lot of my explanations, we have to start from the beginning.

The C++ iterator model has a number of iterator categories: input, forward, bidirectional, random access, and (since C++20) contiguous. This post only needs to consider the first two.

An input range (a range whose iterator is an input iterator) is a single-pass range. You can only ever call begin() one time on it. You can’t have multiple different input iterators into the same range - incrementing one immediately invalidates any existing copies.

CppCon 2022 How Microsoft Uses C++ to Deliver Office - Huge Size, Small Components -- Zachary Henkel

cppcon-2022-how-microsoft-uses-cpp-to-deliver-office-huge-size-small-compon.pngRegistration is now open for CppCon 2023! The conference starts on October 1 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 2023!

How Microsoft Uses C++ to Deliver Office - Huge Size, Small Components

by Zachary Henkel

Summary of the talk:

Office is one of the largest and longest-lived C++ codebases in the world. Over 40 years Office has evolved from a single application written in C for DOS to a product containing over 100M lines of C++ code targeting more than a dozen platforms. What are the implications of growing to this size and what sort of engineering is required? In this talk I’ll give a glimpse behind the curtain on the C++ engineering and architecture in Office. In addition to sharing some details on the scale of Office, I’ll describe the design and coding standards used to create well-factored components that we have termed liblets.

CppCon 2022 Back to Basics: C++ API Design -- Jason Turner

cppcon-2022-back-to-basics-cpp-api-design-jason-turner.pngRegistration is now open for CppCon 2023! The conference starts on October 1 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 2023!

Back to Basics: C++ API Design

by Jason Turner

Summary of the talk:

Let’s face it: writing a C++ API can be a daunting task. You recognize that APIs are a critical aspect of your code, and you’d like to provide your users with a great experience, but how?

This talk will focus on one key aspect: "Making APIs Hard to Use Wrong." How do we design APIs that help, instead of hurt, our users?

How To Check If A Pointer Is In A Range Of Memory -- Raymond Chen

RaymondChenPic.pngC language was defined to cover a large range of computer architectures, including many which would be considered museum relics today. It therefore takes a very conservative view of what is permitted, so that it remains possible to write C programs for those ancient systems. (Which weren’t quite so ancient at the time.)

How To Check If A Pointer Is In A Range Of Memory

by Raymond Chen

From the article:

Suppose you have a range of memory described by two variables, say,

byte* regionStart;
size_t regionSize;

And suppose you want to check whether a pointers lies within that region. You might be tempted to write

if (p >= regionStart && p < regionStart + regionSize)

but is this actually guaranteed according to the standard?