Checking Programming Errors at Compile Time
Learn how to check programming errors during compilation using assert and static_assert.
We'll cover the following...
Assert statements are a simple but very powerful tool for validating invariants and contracts between callers and callees in a codebase. It’s possible to check programming errors while executing the program using assert()
. But we should always strive to detect errors as early as possible, and if we have a constant expression, we can catch programming errors when compiling the program using static_assert()
.