List operations, Declaration and initialization of lists – HP Integrity NonStop H-Series User Manual
Page 67
![background image](/manuals/396950/67/background.png)
Click on the banner to return to the user guide home page.
©Copyright 1996 Rogue Wave Software
List Operations
The member functions provided by the list data type are described in more detail below. Note that
while member functions provide basic operations, the utility of the data structure is greatly extended
through the use of the generic algorithms described in Chapters
.
Declaration and Initialization of Lists
Memory Management
There are a variety of ways to declare a list. In the simplest form, a list is declared by simply stating
the type of element the collection will maintain. This can be a primitive language type (such as
integer or double), a pointer type, or a user-defined type. In the latter case, the user-defined type must
implement a default constructor (a constructor with no arguments), as this constructor is in some
cases used to initialize newly created elements. A collection declared in this fashion will initially not
contain any elements.
list
list
list
An alternative form of declaration creates a collection that initially contains some number of equal
elements. The constructor for this form is declared as explicit, meaning it cannot be used as a
conversion operator. This prevents integers from inadvertently being converted into lists. The
constructor for this form takes two arguments, a size and an initial value. The second argument is
optional. If only the number of initial elements to be created is given, these values will be initialized
with the default constructor; otherwise the elements will be initialized with the value of the second
argument:
list
list
list
list
Lists can also be initialized using elements from another collection, using a beginning and ending
iterator pair. The arguments can be any form of iterator, thus collections can be initialized with values
drawn from any of the container classes in the standard library that support iterators. Because this
requires the ability to specialize a member function using a template, some compilers may not yet
support this feature. In these cases an alternative technique using the copy() generic algorithm can be
employed. When a list is initialized using copy(), an insert iterator must be constructed to convert the