One of possible implementations of std::any_invocable proposed in P0288R5.
This paper proposes a conservative, move-only equivalent of std::function.
Such a code:
// requires: C++14
#include <functional>
#include <memory>
struct widget {
// ...
};
int main() {
std::function<void()> f = [w_ptr = std::make_unique<widget>()] { /*...*/ };
}
Will result in:
error: use of deleted function ‘std::unique_ptr<_Tp, _Dp>::unique_ptr(const std::unique_ptr<_Tp, _Dp>&) [with _Tp = widget; _Dp = std::default_delete<widget>]
In other words, we can't store move-only callables in std::function
.
At the same time such a code will work:
std::any_invocable<void()> f = [w_ptr = std::make_unique<widget>()] { /*...*/ };