Jonathan Boccara's blog

Size and Capacity of STL Containers

Published October 13, 2017 - 2 Comments

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 with the STL

Published October 10, 2017 - 2 Comments
partition STL

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 […]

How the STL inserter iterator really works

Published October 6, 2017 - 1 Comment

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 […]

Sorting with the STL algorithms

Published October 3, 2017 - 1 Comment

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, […]

tee: Debug Info With Little Impact On Code

Published September 29, 2017 - 10 Comments
tee C++ debug log

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 Expressive C++17 Coding Challenge

Published September 25, 2017 - 15 Comments
Expressive C++17 coding challenge

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 […]

How to implement the pimpl idiom by using unique_ptr

Published September 22, 2017 - 16 Comments

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 […]

Cppcast: A Show for All C++ Developers

Published September 19, 2017 - 2 Comments

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 […]

How to Return a Smart Pointer AND Use Covariance

Published September 12, 2017 - 11 Comments

Today we’re going to take a big step back on the specific problem of the clone interface we’ve dealt with on the last post. For this Raoul Borges is taking over on this topic to show you a solution to the general problem of smart pointers and covariance in C++. Raoul is a C++ developer […]