Tools.h++ Manual
104011 Tandem Computers Incorporated 22-105
22
RWTValSlist<T>
Synopsis
#include <rw/tvslist.h>
RWTValSlist<T> list;
Description This class maintains a collection of values, implemented as a singly linked list.
This is a value based list: objects are copied in and out of the links that make up
the list. Unlike intrusive lists (see class
RWTIsvSlist<T>
) the objects need not
inherit from a link class. However, this makes the class slightly less efficient
than the intrusive lists because of the need to allocate a new link off the heap
with every insertion and to make a copy of the object in the newly allocated
link.
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:
• A default constructor;
• well-defined copy semantics (
T::T(const T&)
or equiv.);
• well-defined assignment semantics (
T::operator=(const T&)
or equiv.);
• well-defined equality semantics (
T::operator==(const T&)
).
Example In this example, a singly-linked list of
RWDates
is exercised.
Code Example 22-7
#include <rw/tvslist.h>
#include <rw/rwdate.h>
#include <rw/rstream.h>
main()
{
RWTValSlist<RWDate> dates;
dates.insert(RWDate(2, "June", 52));// 6/2/52
dates.insert(RWDate(30, "March", 46));// 3/30/46
dates.insert(RWDate(1, "April", 90));// 4/1/90
// Now look for one of the dates:
RWDate ret;