Articles & Books

Alternative to select-many bitmask -- Krzysztof Ostrowski

Classic interfaces that use bitmask to select many properties at once can be hard to use and very easy to break.

Alternative to select-many bitmask

by Krzysztof Ostrowski

From the article:

Suppose we have an interface that returns some value depending on combination of other values, and we would like get resource of some type R that is common for Alice and Bob. Here is our interface:

R query(std::uint32_t bitmask);

First question arises quickly: what to put into bitmask? There are plenty of values of type uint32_t!

Multiple possible ways to fix our interface and make it much easier to use exist. We will consider three of them.

Template argument deduction for class template constructors -- Simon Brand

Showing how to use C++17 template argument deduction for constructors to get rid of those pesky make functions.

Template argument deduction for class template constructors

by Simon Brand

From the article:

Have you ever found yourself writing std::make_pair or std::make_move_iterator and wondering why we need a helper function to create these objects for us? The answer is a lack of template argument deduction for class template constructors.

[...]

Fortunately, this feature is coming in C++17!

Building a safety critical memory manager for self driving cars -- Illya Rudkin

What does it take to build a C++ memory manager for safety critical applications such as autonomous vehicles?

Codeplay's Safety-Critical Memory Manager

by Illya Rudkin

From the article

In my experience, when implementing an application, the memory management part of its design is very often overlooked. That is also the case when considering the design for a Safety-Critical (SC) system. This blog post talks about why a memory manager should be considered in the design, especially for an SC system, and why the designers of such systems should consider implementing it first, before doing anything else.

Codeplay has created a Safety-Critical Memory Manager (SCMM) as part of its strategy to build an SC tool set, including implementations of open standards (such as OpenCL) for building artificial intelligence in automotive systems. We believe that an SCMM is a fundamental foundation stone to help us achieve and verify the safety goals for our systems in different problem domains.

 

A “sorted view”--Nick Athanasiou

Sorting can be done many ways.

A “sorted view”

by Nick Athanasiou

From the article:

This installment elaborates on the creation of a “sorted_view” utility. The “References” section contains links to the complete code; throughout the article, we provide demos and snippets to showcase and explain the implementations. The section on modernizing the code contains real world applications of the following C++17 features:

  1. structured bindings
  2. template argument deduction for class templates

Order Your Members

How ordering members can impact performance.

Order Your Members

by Jonas Devlieghere

From the article:

The article highlights the impact that different choices regarding the ordering of members in a struct can have on the performance of your code. A lot can be achieved by taking into account some general guidelines.

(Not) detecting bugs--Andrzej Krzemieński

Undefined behaviour can be dangerous.

(Not) detecting bugs

by Andrzej Krzemieński

From the article:

The following code contains a bug. A developer has spent quite some time looking for the source. The intent of this code is to iterate over two vectors simultaneously, from the first up to the one-before-last element. Thus the most interesting tools that will be employed will be boost::zip_iterator and std::prev.

#include <boost/iterator/zip_iterator.hpp>
#include <boost/tuple/tuple.hpp>
#include <vector>

using zip_iter = boost::zip_iterator<
                   boost::tuple<
                     std::vector<int>::iterator,
                     std::vector<int>::iterator
                   >
                 >;
int main()
{
  std::vector<int> v1 = {1, 2, 3, 4, 0};
  std::vector<int> v2 = {2, 3, 5, 7, 0};
    
  zip_iter beg {boost::make_tuple(v1.begin(), v2.begin())};
  zip_iter end {boost::make_tuple(v1.end(), v2.end())};
  
  auto process = [](zip_iter::reference){};
  std::for_each(beg, std::prev(end), process);
}

Add a const here, delete a const there…--Bruce Dawson

Why constness is important in one article. Can be even better with constexpr.

Add a const here, delete a const there…

by Bruce Dawson

From the article:

I just completed a series of changes that shrunk the Chrome browser’s on-disk size on Windows by over a megabyte, moved about 500 KB of data from its read/write data segments to its read-only data segments, and reduced its private working set by about 200 KB per-process. The amusing thing about this series of changes is that they consisted entirely of removing const from some places, and adding const to others. Compilers be weird...

Generate lambdas for clarity and performance--Björn Fahller

A nice way to avoid code duplication and gain in readability:

Generate lambdas for clarity and performance

by Björn Fahller

From the article:

Higher order functions, functions that operate on other functions or returns functions, are familiar to those who have had some experience with functional programming, but they often seems magical to those who have not. Some of those with experience of using higher order functions have a gut feeling that they are expensive to use and prefer to avoid them...