Is it possible to have a struct A
with a move constructor for itself and some constructor which can move from other types (e.g struct B
) but with having a template deduction going on such that the type B
is not hardcoded directly as another move constructor:
struct A{
A()= default;
A(A&&a){ /* A's move constructor */ }
template<typename T>
A(T&&t){
/* (not a move constructor! by std., matches also lvalues)
move from t
(meta programming to check if we can move the type)
*/
}
}
struct B{};
the problem with the above is that
B b;
A a(std::move(b)); // select the templated constructor (which moves)
A a(b); // selects the same copy constructor (which moves but we do not want!!
How does one achieve this?