Module lessons (3/4)
Algorithms STL (<algorithm>, <numeric>) & C++20 Ranges
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
forloops 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::rangesandstd::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
- 11. Sorting and Searching (
std::sort,std::find_if,std::count_if) - 22. Transformations and Reductions (
std::transform,std::accumulate) - 33. Safe Removal:
std::erase_if(C++20) vs Erase-Remove Idiom - 44. C++20
std::rangesand Lazy Views (std::views) - 5Practical exercises
- 6Check for understanding
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.