假设我有一个函数,它是非复制但是可移动的,我该如何将它存储在std ::函数中?即如何编译以下代码? (使用
gcc 4.6)
#include <functional> #include <iostream> struct S { S() = default; S(S const&) = delete; S& operator=(S const&) = delete; S(S&&) { } void operator()() { } }; std::function<void()> func; void make_func() { S s; func = std::bind(std::move(s)); // This won't compile } int main() { make_func(); }