STL Learning Resource
The aim of this page is to learn STL algorithms efficiently. As explained in this post, knowing STL algorithms provide you with a fantastic set of tools to express your intentions in code, making it clearer and more robust. Knowing your STL algorithms also gives you an idea of what types of abstractions are useful, which gives you a model to write your own ones. So we should strive to know our algorithms.
However there are many of them, more than 100 without counting overloads. This is a lot to learn.
For this reason, I have broken them down into groups in order to show how they are related to each other. Also, learning them one bit at a time should make the process as effortless as can be. This is how I learned them, and it is also how I teach them in my company (@Work_at_murex).
New: The World Map of STL Algorithms: the STL algorithms are now the cities in the World Map and the groups of algorithms are the regions. Check it out!
Additionally, there are some things you need to know about the general design of the STL in order to use it efficiently. For this reason, I’ve also included here a section about understanding the STL, just after the algorithms catalogue. Here is the list of groups of algorithms, that I’m fleshing out along with the writing of the corresponding posts. Further down you will find the posts about mastering the STL.
So in the upcoming weeks you’ll see a focus on posts dedicated to the STL, alternating with posts about expressive code in C++ in a more general way. I’m happy to take your feedback about this (comment, Tweet or email) and if you have suggestions about how to make the learning of STL algorithms even more efficient and painless.
Algorithms catalogue
- The World Map of the STL algorithms
- 105 STL Algorithms in Less Than an Hour
- <algorithm>s on sets – video
- How is std::set_difference implemented?
- Searching with the STL: on a range of iterators (1/3) – in a container (2/3) – unknown algorithms (3/3)
- std::transform, a central algorithm
- Predicates on ranges
- Filling <algorithm>s
- Mins and maxes
- Sorting with the STL
- Partitioning
- (std::)Accumulate Your Knowledge On Algorithms
- How to Reorder Collections With the STL
- Moving Ranges Around with STL Algorithms
- <algorithm>s on heaps
- How to Remove Elements from a Sequence Container
- How to Remove Pointers from a Vector in C++ (co-written with Gaurav Sehgal)
- How to Remove Elements from an Associative Container
- How to Remove Duplicates from an Associative Container
Understanding the STL
- The importance of knowing STL <algorithm>s
- Ranges: the STL to the Next Level – Introduction to the Ranges Library
- Making your code expressive with lambdas
- STL function objects: Stateless is Stressless
- Custom comparison, equality and equivalence
- Functors are not dead: the double-functor trick
- Inserting several elements into an STL container efficiently
- The design of the STL
- How to split a string in C++
- Better understand ranges with the new Cartesian Product adaptor
- Move iterators: where the STL meets Move semantics
- is_transparent: How to search a C++ set with another type than its key
- How to Use Overloaded Functions With The STL
- How to Handle Multiple Types in Max Without A Cast
- Size and capacity
- How the insert iterator really works
- How to Use the STL With Legacy Output Collections
- Smart Output Iterators: A Symmetrical Approach to Range Adaptors
- Think of function objects as functions rather than objects
- Is std::for_each obsolete?
- Make Your Containers Follow the Conventions of the STL
- How to pass a polymorphic object to an STL algorithm
- Which One Is Better: Map of Vectors, or Multimap?
- std::iterator is deprecated: Why, What It Was, and What to Use Instead
- How to Access the Index of the Current Element in a Modern For Loop
- How to Transfer unique_ptrs From a Set to Another Set
- How to Retrieve the Firsts from a Collection of Pairs
- Why You Should Use std::for_each over Range-based For Loops
- Overview of std::map’s Insertion / Emplacement Methods in C++17
- The SoA Vector – Part 1: Optimizing the Traversal of a Collection
- The SoA Vector – Part 2: Implementation in C++
- Indexing Data Structures with C++ Scoped Enums
- The Terrible Problem Of Incrementing A Smart Iterator
- STL Algorithms on Tuples
- An Alternative Design to Iterators and Ranges, Using std::optional
- A Map with Two Types of Keys in C++
- How to send an STL collection to a curried object