Example
struct MyObject {
MyObject(int value):value(value) { }
MyObject(MyObject const&o):value(o.value) { }
int value;
};
Assume that the copy constructor does something in addition to be useful. Then
std::function<void()> f() {
MyObject o;
std::vector<int> v;
return [=]() { /* use v and o */ &o; &v; }
}
v and o are first copied into the initial lambda object, which is fine. But then they are again copied everytime the lambda object needs to be moved. Even though v could be moved, but it is not. That's because the lambda does not have an implicit move constructor, because o does not have a move constructor or trivial copy constructor.
Can someone please explain the rationale behind this?