Tools.h++ Manual

104011 Tandem Computers Incorporated 23-13
23
For each type of
RWGOrderedVector
you must include one (and only one) call
to the macro
implement
somewhere in your code for both the
RWGOrderedVector
itself and for its base class
RWGVector
.
Example Here's an example that uses an ordered vector of
RWCStrings
.
Program output:
First
Second
Last
Public constructors
RWGOrderedVector(
val
)(size_t capac=RWDEFAULT_CAPACITY);
Construct an ordered vector of elements of type val. The initial capacity of the
vector will be
capac
whose default value is
RWDEFAULT_CAPACITY
. The
capacity will be automatically increased as necessary should too many items be
inserted, a relatively expensive process because each item must be copied into
the new storage.
#include <rw/gordvec.h>
#include <rw/cstring.h>
#include <rw/rstream.h>
declare(RWGVector,RWCString)
declare(RWGOrderedVector,RWCString)
implement(RWGVector,RWCString)
implement(RWGOrderedVector,RWCString)
main()
{
RWGOrderedVector(RWCString) vec;
RWCString one("First");
vec.insert(one);
vec.insert("Second"); // Automatic type conversion occurs
vec.insert("Last"); // Automatic type conversion occurs
for(size_t i=0; i <vec.entries(); i++) cout << vec[i] << endl;
return 0;
}