Templates and generic programming
T.150
Check that a class matches a concept using `static_assert`
Reason
If you intend for a class to match a concept, verifying that early saves users' pain.
Example
class X {
public:
X() = delete;
X(const X&) = default;
X(X&&) = default;
X& operator=(const X&) = default;
// ...
};
Somewhere, possibly in an implementation file, let the compiler check the desired properties of X:
static_assert(Default_constructible<X>); // error: X has no default constructor
static_assert(Copyable<X>); // error: we forgot to define X's move constructor
Enforcement
Not feasible.
CPL: C-style programming
C and C++ are closely related languages. They both originate in "Classic C" from 1978 and have evolved in ISO committees since then. Many attempts have been made to keep them compatible, but neither is a subset of the other.
C rule summary: