3

If having a c++ class with a pimpl using std::unique_ptr and solving the fact that the pimpl class is incomplete in the header by declaring my own destructor (I know i could also provide a custom deleter, but lets go with the dtor for this one). If following the rule of five, I guess I should then also go ahead and declare copy/move constructors/assignment operators. However, the reason usually (always?) given for rule of five is that declaring one of the special members might indicate that the class has some resource needing special attention, and that is not the case here.

Is it reasonable to make a departure from the rule of five in this scenario if I don't need the class to be copyable for instance?

joaerl
  • 1,012
  • 1
  • 10
  • 21
  • 1
    I see nothing wrong to only declare a (default) destructor – apple apple Apr 09 '22 at 14:22
  • copyable isn't really relevant here imo. – apple apple Apr 09 '22 at 14:24
  • 3
    The point of declaring all of them or none of them is 1. Because of what you said, but 2. Because the rules behind when each one is or is not provided is growing more complex each release. It also helps document your intent. 10 years from now, if you provided a deleted move constructor, I know you don’t want it to move. If you don’t provide one at all, I have no idea what your original intent was. – Taekahn Apr 09 '22 at 14:26
  • @Taekahn That is a very good point. I am a fan of explicitly stating intent. – joaerl Apr 09 '22 at 18:20

0 Answers0