Articles & Books

The Future of Generic Programming -- How to design good concepts and use them well -- Stroustrup

This new paper by Bjarne Stroustrup has been brewing over the holidays, and is now ready for release as a prepublication draft:

Concepts: The Future of Generic Programming
or, How to design good concepts and use them well

by Bjarne Stroustrup

From the draft paper:

Conclusions

Concepts complete C++ templates as originally envisioned. I don’t see them as an extension but as a completion.

Concepts are quite simple to use and define. They are surprisingly helpful in improving the quality of generic code, but their principles – and not just their language-technical details – need to be understood for effective use. In that, concepts are similar to other fundamental constructs, such as functions. Compared to unconstrained templates, there are no run-time overheads incurred by using concepts.

Concepts are carefully designed to fit into C++ and to follow C++’s design principles:

  • Provide good interfaces
  • Look for semantic coherence
  • Don’t force the user to do what a machine does better
  • Keep simple things simple
  • Zero-overhead

Don’t confuse familiarity and simplicity. Don’t confuse verbosity with “easy to understand.” Try concepts! They will dramatically improve your generic programming and make the current workarounds (e.g., traits classes) and low-level techniques (e.g., enable_if – based overloading) feel like error-prone and tedious assembly programming.

Const, Move and RVO--Bartlomiej Filipek

const does not prevent (N)RVO, youhou.

Const, Move and RVO

by Bartlomiej Filipek

From the article:

C++ is a surprising language. Sometimes simple things are not that simple in practice. Last time I argued that in function bodies const should be used most of the time. But two cases were missed: when moving and when returning a value.

Does const influence move and RVO?

Pros and Cons of Alternative Function Syntax in C++--Petr Zemek

Do you know the trailing return type?

Pros and Cons of Alternative Function Syntax in C++

by Petr Zemek

From the article:

C++11 introduced an alternative syntax for writing function declarations. Instead of putting the return type before the name of the function (e.g. int func()), the new syntax allows us to write it after the parameters (e.g. auto func() -> int). This leads to a couple of questions: Why was such an alternative syntax added? Is it meant to be a replacement for the original syntax? To help you with these questions, the present blog post tries to summarize the advantages and disadvantages of this newly added syntax...

Ranges: the STL to the Next Level--Jonathan Boccara

Ranges are coming!

Ranges: the STL to the Next Level

by Jonathan Boccara

From the article:

The C++ Standard Template Library (STL) is a fantastic tool for making code more correct and expressive. It is mainly composed of two parts:

  • The containers, such as std::vector or std::map for instance,
  • The algorithms, a fairly large collection of generic functions that operate amongst others on containers. They are mostly found under the algorithm header.

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