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 […]
Applying a function to each element of a collection of object is a basic use case of manipulating collections, in C++ or anywhere else for that matter. For this, the STL algorithms library offers std::transform. However, std::transform can lead to verbose code, in particular if we have to call it several times. To illustrate, consider this […]
A few years ago Sean Parent presented his famous C++ Seasoning talk, where he recommended avoiding raw for loop and using STL algorithms instead. This made a lot of people sensitive to this topic, and encouraged us to think about how to convert the for loops in our code into more declarative constructs. Recently I encountered a […]
This is a guest post by Anton Vodostoev. Anton is a C++ developer and follower of Fluent C++. I liked the idea of creating different types of smart iterators when reading the articles “About Smart Output Iterators” by Jonathan. One of them suggested me an idea I wanted to talk about. The problem Imagine we […]
What does is mean to compare two collections of objects to determine which collection is smaller? Even if comparison is natural for some types, comparing compound types that contain them can be trickier. For example, real numbers have a natural order (1.414 is smaller than 3.14) but complex numbers don’t have an order (1 + […]
While working on a project involving bitsets, I had to implement a function that adds 1 to a binary number represented by a bitstet. In this article, we will compare how to implement such a function by using a for loop VS using STL algorithms. C++ has two types of bitsets. The first type are […]
This is a guest post written by Gary Taverner. Gary works for Marlan Maritime Ltd, a company concerned with maritime safety and the monitoring/mapping/management of changing coastline using radar. In this article we examine some code that was difficult to understand only a week after it was written, and how by using the STL it […]
Merging identical consecutive elements in a collection is a recurring need, in C++ or elsewhere in programming. For example, we could want to aggregate a collection of hourly results into a collection of daily results: all the results of each day get aggregated into one for that day. In this case, being “identical” means being […]
After seeing how to extract words among spaces in C++, we are going to see another algorithm that, seen from the outside, does something very different, but has a similar implementation: merging identical consecutive elements in a collection. We will use STL algorithms to implement this, and strive for writing code as expressive as possible. You’ll […]
In this post we’re going to go through a simple example of pipe to add to the C++ pipes library: the tee pipe. This example serves as a tutorial to add a pipe to the library, if you’d like to add one and submit a pull request. We’re going to see: How to write a […]