Jonathan Boccara's blog

How to Pass Class Member Functions to STL Algorithms

Published March 6, 2020 - 0 Comments

The C++ standard library makes it easy to use free functions with its STL algorithms. For example, with std::transform, we can write code like this: auto const inputs = std::vector<int>{1, 2, 3, 4, 5}; auto const results = std::vector<int>{}; std::transform(begin(inputs), end(inputs), back_inserter(results), myFunction); This has the effect of calling myFunction on each element of inputs and putting […]

C++ Regex 101

Published February 28, 2020 - 0 Comments

Since C++11, the C++ standard library contains the <regex> header, that allows to compare string against regular expressions (regexes). This greatly simplifies the code when we need to perform such operations. The <regex> header comes with a lot of features, and it might not be easy to know where to start. The first time I used it, […]

Coding Styles With Exotic Constraints

Published February 25, 2020 - 0 Comments

This article is NWH, standing for Not Written Here. The concept of NWH is inspired from the NIH (Not Invented Here) syndrome which consists in refraining from using existing code from outside the company and reinventing the wheel every time. Just like it is good practice to look out for solutions developed elsewhere, we’re going […]

Virtual, final and override in C++

Published February 21, 2020 - 0 Comments

C++11 added two keywords that allow to better express your intentions with what you want to do with virtual functions: override and final. They allow to express your intentions both to fellow humans reading your code as well as to the compiler. However, as we will see, the intention of override is super useful, but the intention of final… […]

How to Make for_each Stop When a Condition Is True

Published February 18, 2020 - 0 Comments

std::for_each applies a function to each of the elements within a range: std::for_each(begin(v), end(v), f); But it doesn’t allow to stop somewhere in the range, when a condition becomes true on an element. Let’s see how to achieve this by using STL algorithms, and with more modern C++ libraries such as ranges and pipes. Stopping std::for_each […]

How to Make for_each Stop After N Elements

Published February 14, 2020 - 0 Comments

for_each is an STL algorithm that takes a range (in the form of two iterators) and a function, and applies the function to each element of the range: std::for_each(begin(v), end(v), f); // applies f to each element of v It is arguably the simplest algorithm of the STL library. But it is so simple that sometimes […]

Reverse For Loops in C++

Published February 11, 2020 - 0 Comments

This is a guest post by Carlos Buchart. Carlos is one of the main C++ developers at the Motion Capture Division of STT Systems, author of HeaderFiles (in Spanish) and a Fluent C++ follower. As we saw when working on dynamic bitsets, it can be useful to traverse a collection backwards, from its last element […]

My Interview on Software Engineering Radio

Published February 4, 2020 - 0 Comments

I was on the Software Engineering Radio podcast, and I’m very excited about it. Indeed, Software Engineering Radio is a programming podcast that conducts in-depth interviews with software professionals, and it’s the best I know for general topics in programming. With se-radio, you’re sure to learn things every time you listen to an episode (at […]

1 9 10 11 12 13 45