The point of this article is to show why we should think of function objects as functions and not as objects, and what practical consequences this implies for writing code. This perspective is somewhat not natural at first sight, and there is a lot of code out there that doesn’t seem to treat function objects like […]
If there’s one algorithm that lets you do all sorts of things, that must be std::accumulate. It is important to know how to use it, and also how not to use it. This post is part of the STL Learning Resource. Basic usage Numeric types The first thing to know about std::accumulate is its location: the […]
Size and capacity are concepts that look somewhat similar from afar. But mixing them up can lead to under-optimized or even plain wrong code. This article explains all about size and capacity of standard containers, and how these two concepts differ. A big thanks to Stephan T. Lavavej, who kindly provided his feedback on the […]
Partitioning a collection consists in reordering it so that the elements that satisfy a given predicate are moved up to the beginning, and those that don’t satisfy it are moved down after them. The first element that does not satisfy the predicate is called the partition point. This is also the end of the subrange of elements […]
The inserter iterators such as std::back_inserter and std::inserter are important components in the STL that participate in letting us improve the expressiveness of our code. Here we delve into std::inserter. We’ll start with a basic question concerning how it can work, have a peek at the inside, and answer that question. This will make us better understand […]
C++ offers more functionalities about sorting that meets the eye. Let’s see what the STL and Boost can do on this topic. Sorting a whole range The standard function to sort a whole range is std::sort. It operates in O(n*log(n)) and applies the sort directly on the passed range. The comparison used is operator< by default, […]
I’d like you to meet tee, a little companion for retrieving targeted runtime info, with very, very little impact on the code. It’s simple, but I find it very convenient. You can put tee in your code wherever you need to know what’s going on, and tee will spy it for you. Its most basic implementation is […]
The ink is dry on C++17! Actually it had dried a few times already. But the drier the ink, the sooner we get to use this new standard in production code. Now how do we learn all those new additions to the language? And how do we know to use them to write even more […]
The pimpl, standing for “pointer to implementation” is a widespread technique to cut compilation dependencies. There are a lot of resources about how to implement it correctly in C++, and in particular a whole section in Herb Sutter’s Exceptional C++ (items 26 to 30) that gets into great details. There is one thing that I’ve found […]
I had the privilege to be a guest on CppCast last week. On top of sharing this episode with you, I’d like to take a moment to describe why I think the show can be useful to you as a C++ developer. I’ll share my perspective both as a regular listener and as a guest […]