Suppose I have a functor s, which is noncopyable but movable, how can I store it in a std::function? i.e, how to make the following code compile? (using 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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With