Is std::function really the best we can do?
summary
Shows that std::function has predictable runtime and memory overhead and that replacing it with template-based delegates plus small-object in-place storage (using placement new) can be much faster and smaller. Implements and compares designs: raw function-pointer, capture-object, and specialized-template delegates with in-place storage, and presents microbenchmarks and code showing up to 6× speedups and large memory savings for small callables, plus guidance on when those alternatives are safe versus when std::function’s generality is worth the cost.
AI-written summary · about
chapters (9)
- 0:00std::function limitations
- 5:49Why std::function feels magic
- 12:06Lambda capture mechanics
- 21:24Function pointers vs std::function
- 27:03Performance trade-offs
- 35:13Memory optimization
- 42:18Real-world abstractions
- 49:08Alternatives to std::function
- 57:47Q&A
related talks
01h 10mstd::function: a deep dive behind the curtain
01h 10mstd::function: a deep dive behind the curtain
57mstd function, past, present, future
01h 01mUsing Modern C++ to Eliminate Virtual Functions
54mModern Template Techniques
01h 09mFunctional Programming in C++
59mTaming Lambdas' uniqueness
01h 01mCalling Functions: A Tutorial
