1

Good day everyone.

We've got a codebase where some of our classes are generated by scripts. A few dozens of these classes are just containers, i.e. just private members and getters/setters for those. For some reason the person who developed the script decided that they need destructors(with empty body), even though strings/shared_ptrs can perfectly clean up after themselves.

My question is, if I remove the code that generates the destructor, does it mean that the compiler will automatically generate the move contstructor/move operator= for those classes?

My platform is Windows / VC++ 2015, but I'd be interested to know what other compilers do.

Thanks, Michael

MUXCAH
  • 205
  • 1
  • 6
  • 1
    Did you try it? What happened? – nicomp Jan 07 '19 at 14:54
  • @NathanOliver It does answer the question from the POV of C++ standard. I just wanted to know other people's experience, in terms of efficiency improvements. – MUXCAH Jan 07 '19 at 15:01
  • @nicomp Doing some benchmarking as we speak. – MUXCAH Jan 07 '19 at 15:02
  • @MUXCAH There is no performance benefit for the class itself but it can have an effect on the things that use it. For instance, once you provided a destructor your class is no longer trivially destructible, even if all it contains is `int` members. This would stop optimizations in `std::vector` from using `std::memcpy` (which normally is faster). You should prefer the implicitly generated special member functions since it is less work to get them and they can allow for optimizations in the things that use them. – NathanOliver Jan 07 '19 at 15:08
  • @NathanOliver Yes, the classes I was talking about are used heavily in places where performance matters. Thanks for your input. – MUXCAH Jan 07 '19 at 15:21

0 Answers0