On preconditions, and their compile time enforcement with static_assert
and a dash of regex
.
Preconditions, Part 1
by Andrzej Krzemieński
In this post, I want to share my thoughts about the notion of precondition. In “Design by Contract” philosophy, preconditions are always mentioned along postconditions and invariants, and in the context of OO design. In this post I focus only on preconditions and not necessarily related to any class. For instance, the following function specifies a precondition on its argument:
double sqrt(double x); // precondition: x >= 0Note that the function specifies the precondition even though there is no language feature for this purpose (at least in C++). A precondition is a “concept” or an “idea” rather than a language feature. This is the kind of preconditions that this post is about.
Add a Comment
Comments are closed.