Tools.h++ Manual
22-52 104011 Tandem Computers Incorporated
22
RWTPtrSlist<T>
Synopsis
#include <rw/tpslist.h>
RWTPtrSlist<T> list;
Description This class maintains a collection of pointers to type
T
, implemented as a singly-
linked list. This is a pointer based list: pointers to objects are copied in and out
of the links that make up the list.
Parameter
T
represents the type of object to be inserted into the list, either a
class or built in type. The class
T
must have:
• well-defined equality semantics (
T::operator==(const T&)
).
Example In this example, a singly-linked list of
RWDates
is exercised.
Code Example 22-4
#include <rw/tpslist.h>
#include <rw/rwdate.h>
#include <rw/rstream.h>
main()
{
RWTPtrSlist<RWDate> dates;
dates.insert(new RWDate(2, "June", 52)); // 6/2/52
dates.insert(new RWDate(30, "March", 46)); // 3/30/46
dates.insert(new RWDate(1, "April", 90)); // 4/1/90
// Now look for one of the dates:
RWDate key(2, "June", 52);
RWDate* d = dates.find(&key);
if (d){
cout << "Found date " << *d << endl;
}
// Remove in reverse order:
while (!dates.isEmpty()){
d = dates.removeLast();
cout << *d << endl;