C++ Fundamentals - Algorithms
summary
Uses a Simpsons vector to show concrete replacements for raw loops: finding the youngest with min_element with projection (fixes custom compare), grouping kids with ranges::partition and stable_partition + rotate, and summing ages with accumulate vs reduce (demonstrates identical assembly for accumulate and warns that reduce with execution policy par enables parallelism but can change order/accuracy). Calls out pitfalls: accumulate init-type deduction (use 0.0 for doubles) and rotate’s undefined behaviour if the middle iterator isn’t in-range.
AI-written summary · about
chapters (23)
- 0:00Introduction
- 1:50STL as toolbox
- 2:33Simpsons code example
- 5:21Maggie critiques Bart’s loop
- 7:04std::min_element with lambda
- 10:36C++20 ranges min_element
- 13:08Avoid raw loops
- 14:12Bart’s flawed partition
- 16:00std::swap over manual
- 17:26std::partition for grouping
- 19:10C++20 ranges partition
- 21:17Stable partition for order
- 23:27Rotating ranges and undefined behavior
- 24:57C++20 ranges rotate
- 25:19Summing ages with accumulate
- 28:33Avoid init-then-modify
- 31:45Accumulate complexity
- 33:52Accumulate type deduction
- 36:04Parallel sums with reduce
- 37:52Execution policies
- 40:21Raw loops vs algorithms
- 42:48Learning resources
- 45:15Takeaways and closing remarks
related talks
01h 01mAlgorithm Intuition (part 2 of 2)
56mBeginners Guide to C++'s Best Kept Secret -- std::algorithm
01h 01mAlgorithm Intuition (part 1 of 2)
57mRange Algorithms, Views and Actions: A Comprehensive Guide
01h 04mBetter Code: Data Structures
01h 25mComparing 'Classic C++' and 'Modern C++' Ways to Solve Programming Tasks
57mSome Things C++ Does Right
01h 35mThe Twin Algorithms
