Higher-order Functions in C++: Techniques and Applications
summary
Argues that std::function’s common implementation forces unnecessary indirections and copyability, demonstrates a type-erasure implementation using a stored invoke pointer plus void data, and shows how that yields fewer pointer dereferences and fewer allocations when constructed from std::ref. Presents function_ref for cheap synchronous callbacks and a proposed unique_function* (P0288) to accept move-only callables, explains lifetime trade-offs, points to P0045 for const-call operator fixes, and reports that the alternative designs reduce calls/allocations at the cost of explicit reference semantics.
AI-written summary · about
chapters (17)
- 0:00Introduction
- 1:04What is a higher-order function
- 3:35Callable objects in C++
- 5:53Function pointers limitations
- 8:28std::function and type erasure
- 12:06Alternative type erasure implementation
- 17:02Problems with std::function
- 23:11Template arguments for callables
- 27:59Overload set passing proposal
- 32:25Code bloat and compiler optimizations
- 37:09Lifetime management in function_ref
- 41:31Ownership semantics for functions
- 46:52std::reference_wrapper drawbacks
- 51:14Ownership erasure technique
- 54:01Unique function proposal
- 55:33Takeaways and best practices
- 59:39Q&A session
related talks
01h 01mHigher-order functions in Modern C++: existing techniques and function_ref
01h 01mfunctional: What's New, And Proper Usage
01h 02mFunctional C++
01h 01mFunctional C++
01h 04mFunctional C++ For Fun And Profit
49mThe Evolution of Functional Programming in C++
49m“Applying functional programming in code design"
01h 31mFunctional Programming in Modern C++: The Imperatives Must Go!
