With the growing use of recent C++ classes such as std::unique_ptr
I find a lot of classes that use them for their members cannot be copied by default. This is good, as they, well, can't be copied: those members need to be taken care of explicitly if the parent class has to be copyable.
However I find overloading copy constructors/operator to be inconvenient. Each member needs to be explicitly copied, even those that don't need special treatment. What's more, when a member is added, the code maintainer has to remember to add this member to the copy functions too. I find the probability that this code maintainer will fail to do so is close to one when that is me. (I am aware that at least one can have the operator= rely on the copy constructor).
So I was wondering if there would be efficient ways to overload the copy constructors/operator so that no code needs to be written for members that shall be default-copied.
One solution I could think of would be to split the class in two: put in a base class members that default-copy and the rest in a child class; overload copy of the child class only. I feel this is a bit inelegant and I am sure it has drawbacks.
Another would be to be wrap non-copyable objects into classes that, when copied, construct the underlying non-copyable object. This is perhaps better but it is useful only when those objects can be initialized independently of the other parent class members.
If anyone has thoughts or experience to share with how they address this or not for copy, I would be glad to hear it.