loading...

The big STL Algorithms tutorial: Introduction

sandordargo profile image Sandor Dargo ・2 min read

C++ STL Algorithms Tutorial (14 Part Series)

1) The big STL Algorithms tutorial: Introduction 2) The big STL Algorithms tutorial: all_of, any_of, none_of 3 ... 12 3) The big STL Algorithms tutorial: for_each 4) The big STL Algorithms tutorial: find et al. 5) The big STL Algorithms tutorial: the rest of non-modifying sequence operations 6) The big STL Algorithms tutorial: modifying sequence operations - copy et al. 7) The big STL Algorithms tutorial: modifying sequence operations - move and swap 8) The big STL Algorithms tutorial: transform 9) The big STL Algorithms tutorial: transform's undefined behaviour 10) The big STL Algorithms tutorial: modifying sequence operations - replace* 11) The big STL Algorithms tutorial: modifying sequence operations - fill and generate 12) The big STL Algorithms tutorial: replace N elements 13) The big STL Algorithms tutorial: modifying sequence operations - remove calls 14) The big STL Algorithms tutorial: modifying sequence operations - turn things around

I've already written quite a few articles about features introduced by C++ 11 and how much it changed how I look at the language. The feature I liked the most is probably the one of lambda expressions. I don't like them for their sheer existence, it's not l'art pour l'art, but it really helps using the different STL algorithms. If you want to get a quick introduction to all the 105, have a look at this video by the owner of fluentcpp.com.

How I write C++ code changed a lot due to the combination of lambdas and STL algorithms. Yet I know that I don't a lot and I want to improve my knowledge on the STL. What's the best way to learn? Either by doing it or by teaching it. I'm already doing it, so is why hereby I'm starting to write a series on the STL algorithms.

I don't know yet, how frequently I'll write about them and how many I'll cover in one article, but every second technical article I'll write will be about the STL algorithms - the order of publication is another question.

Let's get started!

The algorithms we are going to discuss are basically a set of functions that we can use well together with STL containers and another common point is that they all can be found in the header.

According to cplusplus.com, we can categorize them into 8 groups plus others:

  • Non-modifying sequence operations (e.g. all_if, any_of, find)
  • Modifying sequence operations (e.g. copy, copy_if, transform)
  • Partitions (e.g. partition, is_partition)
  • Sorting (e.g.sort, is_sorted)
  • Binary search (e.g. binary_search, lower_bound, upper_bound)
  • Merge (e.g. merge, set_union)
  • Heap (e.g. push_heap, pop_heap)
  • Min/max (e.g.min, max...)
  • Others

Some groups I'll show you in one post, like min/max, but some other groups which are way bigger, like Non-modifying sequence operations I'll break down into smaller chunks.

Stay tuned!

This article has been originally published on my blog.

C++ STL Algorithms Tutorial (14 Part Series)

1) The big STL Algorithms tutorial: Introduction 2) The big STL Algorithms tutorial: all_of, any_of, none_of 3 ... 12 3) The big STL Algorithms tutorial: for_each 4) The big STL Algorithms tutorial: find et al. 5) The big STL Algorithms tutorial: the rest of non-modifying sequence operations 6) The big STL Algorithms tutorial: modifying sequence operations - copy et al. 7) The big STL Algorithms tutorial: modifying sequence operations - move and swap 8) The big STL Algorithms tutorial: transform 9) The big STL Algorithms tutorial: transform's undefined behaviour 10) The big STL Algorithms tutorial: modifying sequence operations - replace* 11) The big STL Algorithms tutorial: modifying sequence operations - fill and generate 12) The big STL Algorithms tutorial: replace N elements 13) The big STL Algorithms tutorial: modifying sequence operations - remove calls 14) The big STL Algorithms tutorial: modifying sequence operations - turn things around

Posted on by:

sandordargo profile

Sandor Dargo

@sandordargo

Happy father. Blogger. Developer. Amateur of graph databases.

Discussion

markdown guide
 

Super excited to see where this series goes!

Confirmation on "learning by teaching." My Python skills have grown exponentially just through writing my "Dead Simple Python" series.

 

Thanks for your comment!

We are at about 1/4th and we have a lot to go. For months, I've been on the following schedule. 1st week: technical post. 2nd week: some softer topic. 3rd week: book review. So it's still at least a year to get to the end.

And indeed, I've already learned a lot. And that was one of my main goals. To understand these functions better and if I can help others doing so, it's even better.