All posts in "STL"

Introduction to the C++ Ranges Library

Published February 9, 2018 - 2 Comments
C++ ranges

Announcement: This Sunday I’ll be hosting my first AMA, standing for Ask Me Anything, and I’d love for you to join in! An AMA is an online event where you can ask any question to the host. And the AMA I’ll be hosting is about writing clear code (in particular in C++)! So I will take […]

How is std::set_difference Implemented?

Published January 12, 2018 - 2 Comments
C++ STL set_difference

In last week video, we saw the algorithms on sets that the STL provides. We saw how you can use them to manipulate sorted collections in your code, in an expressive manner. Sean Parent said in one of his talks that we should be as familiar with STL algorithms as possible, and take this to the […]

STL Algorithms on Sets

Published December 29, 2017 - 2 Comments
STL algorithms sets C++

If you want to become proficient at manipulating collections in C++, you have to know your STL algorithms. And in particular, you have to know your STL algorithms on sets. The algorithms on sets are less famous than the classical std::for_each or std::accumulate algorithms but they are just as useful, if not more. The algorithms on sets include […]

How to Use the STL With Legacy Output Collections

Published November 24, 2017 - 4 Comments
STL legacy code

When you start using the STL and its algorithms in your code, it’s a bit of a change of habits. And then after a while you get used to it. Then it becomes a second nature. And then even your dreams become organized into beautifully structured ranges that fly in and out of well-oiled algorithms. […]

(std::)Accumulate Knowledge On STL Algorithms

Published October 17, 2017 - 0 Comments

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 of STL Containers

Published October 13, 2017 - 0 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 […]