I often find myself writing tedious move constructors for classes with many member variables. They look something like the following:
A(A && rhs) :
a(std::move(rhs.a)),
b(std::move(rhs.b)),
c(std::move(rhs.c)),
d(std::move(rhs.d)) {
some_extra_work();
}
That is, they perform all of the actions associated with the default move constructor, then peform some mundane extra task. Ideally I would delegate to the default move constructor then perform the extra work, however the act of defining my own move constructor prevents the default implementation from being defined, meaning there's nothing to delegate to.
Is there a nice way to get around this anti-pattern?
A
into two classes and put one into another? One will have all default constructors and other one will dosome_extra_work
. Check Rule of zero.A(A&& rhs, int) : A(rhs){}
not work?rhs.d = 0;
).