Consider the classic approach to make the class incompatible:
// similar to boost::noncopyable class noncopyable { protected: constexpr noncopyable() = default; noncopyable(const noncopyable&) = delete; noncopyable& operator=(const noncopyable&) = delete; }; class c: private noncopyable { /* ... */ };
As the declaration of any copy operation prevents the automatic creation of move operations, it automatically makes all derived classes immovable (by default) as well (so the noncopyable full name will be noncopyable_and_nonmoveable ).
Now let's look at the classic unpublished classes from the standard library, for example. unique_ptr . It is not copyable, but movable, otherwise its utility will be limited. I believe this is true for many other cases.
In fact, I cannot come up with any example when a class should be executed without moving. My argument is that even if the class is not planned to be moved there, this can be done with an error that can be harmful.
There are actually two related questions:
1) Why is boost::noncopyable also not moving? This causes problems:
struct c: private boost::noncopyable { std::unique_ptr<Something> something; c(c&&) = default; c& operator=(c&&) = default; };
not working ( wandbox ) - move operations cannot be generated because they are not generated for the base class. You need to execute them manually → list your members → maintenance → errors. Just unlocking the move operations in noncopyable will solve the problem.
2) What are the uses when portability is harmful, so should it be prevented?
source share