All posts in "STL"

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

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

How to Handle Multiple Types in Max Without A Cast

Published August 18, 2017 - 4 Comments

Today I want to share with you an interesting technique shown by Arthur O’Dwyer in his CppCon talk, Template Normal Programming, to deal with min and max on different types. Arthur has kindly accepted that I share this content with you on Fluent C++. This will be a shorter post, fit for summer as you […]

Move iterators: where the STL meets Move semantics

Published April 25, 2017 - 3 Comments
move iterators

In C++11, a host of new features were introduced in the language and the Standard Library, and some of them work in synergy. Move iterators are an example of how the STL collaborates with move semantics, to allow expressing several important concepts in a very well integrated piece of code. Well, almost. By using the native features only, we don’t get […]

How to split a string in C++

Published April 21, 2017 - 20 Comments

How to split a string in C++? That is to say, how to get a collection of substrings representing the words of a sentence, or the pieces of data contained in a CSV entry? This is a simple question, but one which has multiple answers in C++. We will see 3 solutions, each one having advantages and […]