On Thursday 21 August 2014 16:08:40 Peter Dimov wrote:
John Maddock wrote:
1) Why on earth is:
BOOST_CONSTEXPR noncopyable() = default;
Better than
noncopyable() {}
I can tell you what's the difference, but not why it's better. :-)
=default makes the constructor trivial. A trivial constructor can be omitted. It's not clear to me why a noncopyable class would need to have a trivial constructor.
Similarly, =default on the destructor instead of {} makes it trivial. A trivial destructor may be omitted. It makes approximately zero sense for a noncopyable class to have a trivial destructor.
Why do you think it's not sensible to have a trivial default constructor/destructor for a non-copyable class? I don't think noncopyable should guess on user's class semantics. It should do exactly what it is required to and nothing more, and defaulted functions achieve that.
The funniest part is that =delete on the copy constructor makes the copy constructor trivial as well, in C++11. A trivial copy constructor means that the class is copyable with memcpy. :-)
Technically, you can apply memcpy to any object and deal with the consequences. I don't see why noncopyable should attempt to do anything about it (and having non-trivial constructor actually doesn't do anything about it).