Chapter 8. Constraints

 

I see, and I do not understand. I hear, and I forget. I do, and I remember.

 
 --Proverb
 

The average man doesn’t want to be free. He wants to be safe.

 
 --Henry Louis Mencken

A constraint is a condition that one software element places on another, at compile time, in order for them to successfully interoperate. Constraints may be thought of as compile-time contract enforcements. I bang on at great length about constraints in Section 1.2 of Imperfect C++. My editor would be quite distraught if I were to repeat that material here, so I will just describe the two main types of constraints supported by the language and give a couple of examples of each.

Type System Leverage

The classic constraint given by Bjarne Stroustrup (in a ...

Get Extended STL, Volume 1: Collections and Iterators now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.