None
NO
GotW #101: Preconditions, Part 2 (Difficulty: 7/10)
['Herb Sutter', 'View All Posts Herb Sutter', 'Herb Sutter Is An Author', 'Speaker', 'A Technical Fellow At Citadel Securities. He Serves As Chair Of The Standard C', 'Foundation', 'Its Conference Cppcon', 'Served As Chair Of The Iso C', 'Standards Committee To']
Sutter’s Mill
Consider these three examples, where each shows expressing a boolean condition either as a function precondition or as an encapsulated invariant inside a new type: // (a) A vector that is sorted template <typename T> void f( vector<T> const& v ) [[pre( is_sorted(v) )]] ; template <typename T> void f( sorted<vector<T>> const& v ); // (b) A vector that is not empty template <typename T> void f( vector<T> const& v ) [[pre( !v.empty() )]] ; template <typename T> void f( not_empty<vector<T>> const& v ); // (c) A pointer that is not null void f( int* p ) [[pre( p != nullptr )]] ; void f( not_null<int*> p ); “Contracts, preconditions and invariants” (Andrzej’s C++ blog, December 2020).