Preconditions, Part 1 -- Andrzej Krzemieński

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 >= 0

Note 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.

Continue reading...

Add a Comment

Comments are closed.

Comments (0)

There are currently no comments on this entry.