Say I have the following class:
class test {
A a;
B b;
C c;
public:
test(A const& a_in, B const& b_in, C const& c_in) : a(a_in), b(b_in), c(c_in){}
}
Now, if any of the parameters to the constructor are rvalue references, I would obviously want to use move semantics instead of copying. However, since each parameter might (or might not) be passed in as an rvalue reference, this means I would have to write eight different constructors, one for each possible combination of rvalue references:
class test {
A a;
B b;
C c;
public:
test(A const& a_in, B const& b_in, C const& c_in) : a(a_in), b(b_in), c(c_in){}
test(A const& a_in, B const& b_in, C &&c_in) : a(a_in), b(b_in), c(c_in){}
test(A const& a_in, B &&b_in, C const& c_in) : a(a_in), b(b_in), c(c_in){}
test(A const& a_in, B &&b_in, C &&c_in) : a(a_in), b(b_in), c(c_in){}
test(A &&a_in, B const& b_in, C const& c_in) : a(a_in), b(b_in), c(c_in){}
test(A &&a_in, B const& b_in, C &&c_in) : a(a_in), b(b_in), c(c_in){}
test(A &&a_in, B &&b_in, C const& c_in) : a(a_in), b(b_in), c(c_in){}
test(A &&a_in, B &&b_in, C &&c_in) : a(a_in), b(b_in), c(c_in){}
}
Even for just three parameters, this is already a terrible mess. Is there a better way?