Tools.h++ Manual

104011 Tandem Computers Incorporated 15-15
15
These functions return the first or last item in the collection, respectively, or nil
if the collection is empty.
virtual size_t index(const RWCollectable*) const;
This function returns the index of the first object that is equal to the argument
or the special value "
RW_NPOS
" if there is no such object:
RWOrdered od;
od.insert(new RWCollectableInt(6)); // 6
od.insert(new RWCollectableInt(2)); // 6 2
od.insert(new RWCollectableInt(4)); // 6 2 4
RWCollectableInt dummy(2);
size_t inx = od.index(&dummy);
if (inx == RW_NPOS)
cout << "Not found.\n";
else
cout << “Found at index “ << inx << endl;
Program output:
1
Use the following function to insert an item at a particular index:
virtual RWCollectable* insertAt(size_t, i,
RWCollectable* c);
RWOrdered od;
od.insert(new RWCollectableInt(6)); // 6
od.insert(new RWCollectableInt(2)); // 6 2
od.insertAt(1, new RWCollectableInt(4)); // 6 4 2