Skip to main content
Module 9 · Lesson 3 of 421/26 in the course~16 min
Module lessons (3/4)

Algorithms STL (<algorithm>, <numeric>) & C++20 Ranges

Lesson preview5 hands-on exercises readyCourse C++ · Module 9 — Move Semantics, Lambda and STL Modern

std::sort, std::find_if, std::accumulate and lazy views std::views::filter | transform without intermediate allocations.

What you'll learn in this lesson

  • Replace bug-prone manual for loops with expressive, self-documenting STL algorithms.
  • Understand the [begin(), end()) semi-open iterator pair model and pass lambdas as predicates.
  • Compose lazy transformations without intermediate allocations using C++20 std::ranges and std::views.

Overview

The Standard Template Library ingeniously separates containers (std::vector, std::array) and algorithms (<algorithm>, <numeric>). Instead of rewriting for loops to search or sort by hand, you combine iterators + lambdas resulting in shorter, clearer, and often compiler-vectorized code!

Traditional algorithms operate on a semi-open interval [first, last), where first is the first element and last points just after the last:

Sections covered in this lesson

  1. 11. Sorting and Searching (std::sort, std::find_if, std::count_if)
  2. 22. Transformations and Reductions (std::transform, std::accumulate)
  3. 33. Safe Removal: std::erase_if (C++20) vs Erase-Remove Idiom
  4. 44. C++20 std::ranges and Lazy Views (std::views)
  5. 5Practical exercises
  6. 6Check for understanding
Pro Lesson · Module 9 — Move Semantics, Lambda and STL Modern

Unlock "Algorithms STL (<algorithm>, <numeric>) & C++20 Ranges" and the full Course C++ curriculum

std::sort, std::find_if, std::accumulate and lazy views std::views::filter | transform without intermediate allocations.

Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.

  • Instant access to all advanced modules in Course C++ plus 17 more courses
  • Hands-on browser exercises with automated test suites and solutions
  • 14-day money-back guarantee processed via Paddle.com

14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.