Tools.h++ Manual
104011 Tandem Computers Incorporated 22-61
22
RWTPtrSortedVector<T>
Synopsis
#include <rw/tpsrtvec.h>
RWTPtrSortedVector<T> sortvec;
Description
RWTPtrSortedVector<T>
is a pointer-based ordered collection. That is, the
items in the collection have a meaningful ordered relationship with respect to
each other and can be accessed by an index number. In the case of
RWTPtrSortedVector<T>
, objects are inserted such that objects "less than"
themselves are before the object, objects "greater than" themselves after the
object. An insertion sort is used. Duplicates are allowed.
Stores a pointer to the inserted item into the collection according to an ordering
determined by the less-than (<) operator.
The class
T
must have:
• well-defined equality semantics (
T::operator==(const T&)
);
• well-defined less-than semantics (
T::operator(const T&)
);
Example This example inserts a set of dates into a sorted vector in no particular order,
then prints them out in order.
Code Example 22-5
#include <rw/tpsrtvec.h>
#include <rw/rwdate.h>
#include <rw/rstream.h>
main()
{
RWTPtrSortedVector<RWDate> vec;
vec.insert(new RWDate(10, "Aug", 1991));
vec.insert(new RWDate(9, "Aug", 1991));
vec.insert(new RWDate(1, "Sept", 1991));
vec.insert(new RWDate(14, "May", 1990));
vec.insert(new RWDate(1, "Sept", 1991)); // Add a duplicate
vec.insert(new RWDate(2, "June", 1991));
for (int i=0; i<vec.length(); i++)