folly::Function: A Non-copyable Alternative to std::function
We have often found it limiting that std::function cannot store callable objects if they are not copyable, so we developed and open-sourced folly::Function, a function wrapper that can store move-only callable objects. This presentation outlines the design decisions behind folly::Function and illustrates their consequences and our experiences after 18 months of wide production use at Facebook. We find folly::Function is more appropriate than std::function for typical use cases, such as storing callback functions and submitting tasks for asynchronous execution. Other features of folly::Function include that it is noexcept-movable, and it avoids some known issues regarding const-correctness in std::function, which allows to invoke non-const operations on a const reference. Instead, folly::Function lets you declare whether a callable may or may not mutate its state (e.g. folly::Function＜void() const＞).