Next : Core components, Previous : Structure of the Library , Top : Table of Contents
To ensure that the different components in a library work together, they must
satisfy some basic requirements. Requirements should be as general as possible,
so instead of saying "class X
has to define a member function
operator++()
," say "for any object
x
of class
X
, ++x
is defined." (It is unspecified whether the
operator is a member or a global function.) Requirements are stated in terms of
well-defined expressions, which define valid terms of the types that satisfy the
requirements. For every set of requirements there is a table that specifies an
initial set of the valid expressions and their semantics. Any generic algorithm
that uses the requirements has to be written in terms of the valid expressions
for its formal type parameters.
If an operation is required to be linear time, it means no worse than linear time, and a constant time operation satisfies the requirement. In some cases the semantic requirements are presented using C++ code. Such code is intended as a specification of equivalence of a construct to another construct, not necessarily as the way the construct must be implemented (although in some cases the code given is unambiguously the optimum implementation).
|