Classes and class hierarchies
C.20
If you can avoid defining default operations, do
Reason
It's the simplest and gives the cleanest semantics.
Example
struct Named_map {
public:
explicit Named_map(const string& n) : name(n) {}
// no copy/move constructors
// no copy/move assignment operators
// no destructor
private:
string name;
map<int, int> rep;
};
Named_map nm("map"); // construct
Named_map nm2 {nm}; // copy construct
Since std::map and string have all the special functions, no further work is needed.
Note
This is known as "the rule of zero".
Enforcement
(Not enforceable) While not enforceable, a good static analyzer can detect patterns that indicate a possible improvement to meet this rule. For example, a class with a (pointer, size) pair of members and a destructor that deletes the pointer could probably be converted to a vector.