Tools.h++ Manual
21-182 104011 Tandem Computers Incorporated
21
Example
Program output:
cat
dog
fish
Public constructors
RWSortedVector(size_t size = RWDEFAULT_CAPACITY);
Construct an empty
RWSortedVector
that has an initial capacity of size items.
The capacity will be increased automatically if excess items are inserted into
the collection.
Public member operators
RWBoolean operator==(const
RWSortedVector& sv) const;
Returns
TRUE
if for every item in self, the corresponding item in
sv
at the same
index is equal. The two collections must also have the same number of
members.
const RWCollectable* operator[](size_t i);
Returns the
i
'th element in the collection. If
i
is out of range, an exception of
type
RWBoundsErr
will be thrown. This function cannot be used as an lvalue.
#include <rw/sortvec.h>
#include <rw/collstr.h>
#include <rw/rstream.h>
main()
{
RWSortedVector sv;
sv.insert(new RWCollectableString("dog"));
sv.insert(new RWCollectableString("cat"));
sv.insert(new RWCollectableString("fish"));
RWSortedVectorIterator next(sv);
RWCollectableString* item;
while( item = (RWCollectableString*)next() )
cout << *item << endl;
sv.clearAndDestroy();
}