Best way to create a setter function in C++
问题 I want to write a template function that receives parameter by move or by copy. The most efficient way that I use is: void setA(A a) { m_a = std::move(a); } Here, when we use is A a; setA(a); // <<---- one copy ctor & one move ctor setA(std::move(a)); // <<---- two move ctors I recently found out that defining it this way, with two functions: void setA(A&& a) { m_a = std::move(a); } void setA(const A& a) { m_a = a; // of course we can so "m_a = std::move(a);" too, since it will do nothing }