Transrangers: An Efficient, Composable Design Pattern for Range Processing -- Joaquín M López Muñoz

Another twist on ranges.

Transrangers: An Efficient, Composable Design Pattern for Range Processing

by Joaquín M López Muñoz

From the article:

Transrangers are a new design pattern for efficient, composable range processing that can be faster than pull-based C++/Range-v3 views whithout losing any expressiveness. The underlying architecture combines ideas from push processing with the internalization of control flow. Transrangers can be used on their own or be leveraged as an implementation detail of range libraries to improve the performance of view-based operations.


How C++ Resolves a Function Call--Jeff Preshing

Know everything about it.

How C++ Resolves a Function Call

by Jeff Preshing

from the article:

C is a simple language. You’re only allowed to have one function with each name. C++, on the other hand, gives you much more flexibility:

  • You can have multiple functions with the same name (overloading).
  • You can overload built-in operators like + and ==.
  • You can write function templates.
  • Namespaces help you avoid naming conflicts.

I like these C++ features. With these features, you can make str1 + str2 return the concatenation of two strings. You can have a pair of 2D points, and another pair of 3D points, and overload dot(a, b) to work with either type. You can have a bunch of array-like classes and write a single sort function template that works with all of them.

But when you take advantage of these features, it’s easy to push things too far. At some point, the compiler might unexpectedly reject your code with errors like:

error C2666: 'String::operator ==': 2 overloads have similar conversions
note: could be 'bool String::operator ==(const String &) const'
note: or       'built-in C++ operator==(const char *, const char *)'
note: while trying to match the argument list '(const String, const char *)'

Like many C++ programmers, I’ve struggled with such errors throughout my career. Each time it happened, I would usually scratch my head, search online for a better understanding, then change the code until it compiled. But more recently, while developing a new runtime library for Plywood, I was thwarted by such errors over and over again. It became clear that despite all my previous experience with C++, something was missing from my understanding and I didn’t know what it was.

Fortunately, it’s now 2021 and information about C++ is more comprehensive than ever. Thanks especially to, I now know what was missing from my understanding: a clear picture of the hidden algorithm that runs for every function call at compile time.

Parameter Passing in C and C++--Scott Wolchok

Let's go down to the metal.

Parameter Passing in C and C++

by Scott Wolchok

From the article:

Now that we know how to read assembly language, we can talk about how parameter passing works at the machine level and its consequences for writing faster code. We will focus on x86_64, but ARM64 works in a roughly similar way...

Concise Result Extraction in Modern C++--David Gorski

Template magic.

Concise Result Extraction in Modern C++

by David Gorski

From the article:

A popular idiom in functional programming is the use of sum types to express results or optional values. When a function returns, it either succeeded and we get the result, or it failed and we have an error on our hands. This is a pattern in Modern C++ as well, enabled by standard library types such as std::variant and std::optional. In this article we will explore how to improve the ergonomics of handling multiple results and potential error values...

How std::any Works--Jonathan Boccara

Lambda magic.

How std::any Works

by Jonathan Boccara

From the article:

In the previous post we’ve seen a very nice technique to use value semantics with inheritance and virtual methods, which was made possible by std::any.

Given its usefulness, it would be interesting to better understand std::any. Indeed, std::any is sometimes said to be “the modern void*“. But it does much more than a void*...

Build Throughput Series: Template Metaprogramming Fundamentals--Xiang Fan

Optimise templates.

Build Throughput Series: Template Metaprogramming Fundamentals

by Xiang Fan

From the article:

Template metaprogramming is popular and seen in many code bases. However, it often contributes to long compile times. When investigating build throughput improvement opportunities in large codebases, our finding is that more than one million template specializations and template instantiations is quite common and often provides optimization opportunities for significant improvement.

In this blog post, I will walk through the differences between template specialization and template instantiation and how they are processed in the MSVC compiler...

4 Features of Boost HOF That Will Make Your Code Simpler--Jonathan Boccara


4 Features of Boost HOF That Will Make Your Code Simpler

by Jonathan Boccara

From the article:

Boost HOF, standing for Higher Order Functions, is a Boost library offering functions that work on functions.

This impressive library provides a lot of advanced components allowing to go a step further into functional programming in C++. In this post, we’ll focus on 4 of the more basic ones (+ a bonus one) that allow to make code simpler in common tasks.

HOF provides one header in the form of #include <boost/hof/XXX.hpp> for each component, as well as a general header #include <boost/hof.hpp>. It is compatible with C++11...

One Trick with Private Names and Function Templates--Bartlomiej Filipek

Will you use it?

One Trick with Private Names and Function Templates

by Bartlomiej Filipek

From the article:

Last time in my blog post about How to Share Code with Const and Non-Const Functions in C++ I had a custom type declared and defined in one place (like in a header file). Recently, I tried to separate the declaration from implementation, and I got into a situation where one private function template was left.

In this article, I’d like to show you one trick that allowed me to convert this function template into a non-member function without giving up private details of the class...