“folly::Function: A Non-copyable Alternative to std::function”
summary
A replacement for std::function that stores move-only callable objects and is deliberately non-copyable, folly::Function is implemented like std::function but sized at 64 bytes with 48 bytes for in-place storage, uses two function pointers for invoke and management, and is noexcept-movable so it works with STL containers and avoids copy-workarounds. Benchmarks show slightly faster invokes (~2.0 ns vs 2.3 ns) and create+invoke (2.8 ns vs 3.0 ns). It enforces const correctness, migrated easily at Facebook after 18 months of production use.
AI-written summary · about
chapters (10)
- 0:00Introduction to callable types
- 1:54Need for function wrappers
- 4:35Standard function overview
- 6:10Facebook use cases
- 10:09Limitations of std::function
- 14:25Introducing folly::Function
- 17:19Implementation details
- 21:11Migration experience
- 23:42Performance benchmarks
- 25:41Q&A and conclusion
related talks
01h 13mNot Leaving Performance On The Jump Table
32mWhy and How to Roll Your Own std::function Implementation
01h 29mHigher-order functions and function_ref
01h 02mFunctional C++
01h 01mHigher-order functions in Modern C++: existing techniques and function_ref
01h 01mFunctional C++
46mPractical Functional Programming in C++
01h 03mFunctional C++ for Fun & Profit
