The Dark Corner of STL in Cpp: MinMax Algorithms
summary
Shows that calling std::min/std::max leads to dangling references when overloads return const references, and that C++14 initializer_list overloads fix lifetimes by returning by value but force initializer_list copies and prohibit moves. Demonstrates const correctness issues that sometimes tempt const_cast and undefined behavior, and builds alternative overload sets and a cleaner C++20 solution that decouples argument types, uses common_reference and perfect forwarding so rvalues move and lvalues don’t — it works but remains ergonomically sharp.
AI-written summary · about
chapters (9)
- 0:00STL min-max intro
- 1:48Why min-max is tricky
- 3:56Dangling references in min-max
- 8:35C++20 vs C++14 min-max
- 12:33Const correctness issues
- 15:22Fixes for min-max problems
- 19:20Custom min-max simplified
- 24:00Optimized custom min-max
- 25:03Summary and cautions
related talks
01h 00mSTL Features And Implementation Techniques
01h 10mAn Overview of C++11/14, Part II
58mUnderstanding and Mastering C++'s Complexity
01h 05mBack To Basics: Overload Resolution
01h 30m50 shades of C++
01h 40mBack to the Basics! Essentials of Modern C++ Style
33mC++: Unexpected Behaviour
50mTwo advanced PMR techniques in C++17/20
