It is my understanding that the current (post-C++11) convention is to write setters with movable types as follows:
void set_a(A a) {
a_ = std::move(a);
}
What is the best way to write another setter or forwarder function that calls this set_a()? For example:
void set_ab(A a, B b) {
set_a(std::move(a)); // like this?
set_b(b); // or like this?
}
Or:
void do_one(A a) { // by value? by const ref? by rvalue-ref?
do_two(a); // move?
}
void do_two(A a) {
obj.set_a(a);
}
I don't think std::move() is appropriate here, so how should I write this for efficiency, assuming an optimizing compiler?
Do all these function signatures depend on whether I'm storing the final A object somewhere or not?
Thanks
Aucun commentaire:
Enregistrer un commentaire