Tools.h++ Manual
18-10 104011 Tandem Computers Incorporated
18
Here’s a slightly more complicated example:
template <class T> void List::insert(T* obj)
{
RWPRECONDITION( obj!= 0 );
head = new Link(head, obj);
RWPOSTCONDITION( this->contains(obj) );
}
The job of this function is to insert the object pointed to by the argument into a
linked list of pointers to objects of type T. The only precondition for the
function to work is that the pointer "
obj"
not be nil. If this condition is
satisfied, then the function guarantees to successfully insert the object. This is
checked by the postcondition clause.
The macros
RWPRECONDITION
and
RWPOSTCONDITION
are defined in
<rw/defs.h>
and compile out to no-ops unless the preprocessor macro
RWDEBUG
has been defined:
#ifdef RWDEBUG
# define RWPRECONDITION(a)assert(a)
# define RWPOSTCONDITION(a)assert(a)
#else
# define RWPRECONDITION(a)((void*)0)
# define RWPOSTCONDITION(a)((void*)0)
#endif