I have a factory method returning a std::function
class Builder {
public:
function<void(Data&)> build();
}
and a functor object
class Processor {
protected:
vector<int> content_;
public:
void operator()(Data&) {
....
}
}
Now I want to return the functor in the factory method, and I write
function<void(Data&)> build() {
Processor p;
// Add items to p.content_
function<void(Data&)> ret(p);
return ret;
}
My question is: will ret
maintain a copy of p
? If so, when p.content_
is large, will that become a burden? What will be a suggested way to implement this?