DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
A List Class Library for C++ - List(C++)

Basic operations

Basic operations on Lists include assignment, concatenation, conversions, length, and comparisons.

Assignment

Assignment for Lists is done with the assignment (=) operator. The statement L1 = L2; destroys the contents of List L1 and replaces them with a copy of the elements in List L2. The return value of an assignment expression is the object assigned, so L1=L2=L3; works as expected.

Concatenation

The plus (+) operator is used for concatenation. If L1 and L2 are both Lists, then L1 + L2 is a new List whose elements are a copy of those of L1 followed by a copy of those of L2. Also, + can be used with a List and a T, so that L+t is a new List whose elements are those of List L followed by t.

Conversions

Coercions from Ts to List<T>s are implemented by the constructor functions for class List<T>. For example, whenever a T is found where a List<T> is expected, the appropriate List<T> constructor function is called to produce a List containing just that element.

Also, whenever a List is used as an expression, for example, while(L), it is converted to a void* automatically so that it can be evaluated as TRUE or FALSE. The expression will be TRUE if the List is nonempty, and FALSE otherwise.

Length

L.length() returns the length (number of elements) of the List<T> L.

Comparisons

The == and != operators are used for comparisons of Lists. L1 == L2 is TRUE if each element of L1 is equal (that is, T::operator==() is nonzero) to the corresponding element of L2. L1 != L2 is TRUE otherwise.


Next topic: Sort operation
Previous topic: Operations on Lists

© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005