I am struggling with passing an callable object with overloaded operator bool. It posses also unique_ptr for data so copying was disabled. I am trying to pass such a object to another object whose constructor takes std::function, I believe it is totally legal.
See example:
#include <functional>
#include <memory>
#include <utility>
using namespace std;
class invoker
{
public:
invoker(function<bool(void)> fnc_):
fnc { move(fnc_) }
{}
~invoker() = default;
private:
function<bool(void)> fnc;
};
class action
{
public:
action() = default;
~action() = default;
action(const action& rhs) = delete;
action& operator=(const action& rhs) = delete;
action(action&& rhs):
data { move(rhs.data)}
{
}
action& operator=(action&& rhs)
{
if (this != &rhs)
{
data = std::move(rhs.data);
}
}
bool operator()()
{
return true;
}
private:
unique_ptr<int> data;
};
int main()
{
auto runner = std::make_unique<invoker>(std::move(action {}));
//unique_ptr<invoker> runner(new invoker(action() ));
return 0;
}
Why does compiler complain?
> /usr/include/c++/5/functional:1710:34: error: use of deleted function
> 'action::action(const action&)'
> __dest._M_access<_Functor*>() =