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