Higher-order functions in Modern C++: existing techniques and function_ref
summary
Covers practical higher-order patterns and proposes function_ref as a lightweight, non-owning callable reference implemented as a void plus function pointer type-erasure. Benchmarks (Google Benchmark, Simon Brand’s impl) show that function_ref is zero-cost when inlined* — matching template callables — while std::function pays large overhead (roughly an order of magnitude slower when inlined); without inlining function_ref is ~2x slower than templates but still faster than std::function. Notes: noexcept propagation, dangling-reference risk (does not extend lifetime).
AI-written summary · about
chapters (52)
- 0:00Introduction
- 1:00Outline
- 1:20Disclaimer
- 1:54Assumptions
- 2:07Higherorder functions
- 2:30Example twice
- 2:58Greater than
- 4:48Signal
- 6:21Bus
- 7:55Overload
- 9:09Use cases
- 9:34Repetition
- 9:59Integration test
- 10:50UI example
- 12:24Inverted control flow
- 17:41Production example
- 19:19Synchronicity
- 19:42BoostFuture
- 21:00enumeratetypes
- 22:42the same obstruction
- 23:07pros and cons
- 24:08Left vs Right
- 25:38Left Guard
- 26:39Benchmarking
- 26:56Iterators vs Highorder Functions
- 28:11Filter Iterator
- 28:40Highorder function
- 29:11Highorder duration
- 32:33Questions
- 32:48pointers to functions
- 33:27template parameters
- 34:40city function
- 35:38functionref
- 37:21why use functionref
- 38:12interface
- 39:06use case example
- 41:30packagecache example
- 42:54state change callback
- 44:04implementation
- 45:02construction
- 47:15invocation
- 48:08no accept
- 49:12the bad
- 50:41conceptsper
- 51:33benchmarks
- 52:11template parameter
- 52:31tests
- 54:21conclusions
- 55:30design decisions
- 57:33assignment operator
- 58:33reference wrapper
- 59:28multifunctionref
related talks
01h 29mHigher-order functions and function_ref
01h 02mHigher-order Functions in C++: Techniques and Applications
01h 01mfunctional: What's New, And Proper Usage
01h 02mFunctional C++
31mSmart References: There and Back Again
31m“folly::Function: A Non-copyable Alternative to std::function”
01h 01mFunctional C++
01h 04mFunctional C++ For Fun And Profit
