All posts in "STL"

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

No Raw For Loops: Assigning to a Data Member

Published January 10, 2020 - 0 Comments

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

Lower and Upper Bound Insert Iterators

Published December 27, 2019 - 0 Comments

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

Comparing C++ Containers with Lexicographical Comparison

Published December 20, 2019 - 0 Comments

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

How to Increment a Dynamic Bitset with the STL

Published December 17, 2019 - 0 Comments

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

Transforming Deeply Nested Loops With STL Algorithms

Published November 1, 2019 - 0 Comments

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

How to Merge Consecutive Elements in a C++ Collection

Published October 15, 2019 - 0 Comments

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

Code It Yourself: Merging Consecutive Elements in a C++ Collection

Published October 11, 2019 - 0 Comments

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

How to Create Your Own C++ Pipe

Published October 4, 2019 - 0 Comments
tee pipe C++

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