Deitel & Associates, Inc. Logo

Back to www.deitel.com
digg.png delicious.png blinkit.png furl.png
C++ How to Program, 5/e

ISBN:
0-13-185757-6
© 2005
pages: 1500
Buy the Book!
Amazon logo
InformIT logo

[Note: This tutorial is an excerpt (Sections 23.1) of Chapter 23, Standard Template Library (STL), from our textbook C++ How to Program, 5/e. These tutorials may refer to other chapters or sections of the book that are not included here. Permission Information: Deitel, Harvey M. and Paul J., C++ HOW TO PROGRAM, ©2005, pp.1112-1123. Electronically reproduced by permission of Pearson Education, Inc., Upper Saddle River, New Jersey.]

 

23.1.1 Introduction to Containers (Continued)

STL Container Common Functions

All STL containers provide similar functionality. Many generic operations, such as member function size, apply to all containers, and other operations apply to subsets of similar containers. This encourages extensibility of the STL with new classes. Figure 23.2 describes the functions common to all Standard Library containers. [Note: Overloaded operators operator<, operator<=, operator>, operator>=, operator== and operator!= are not provided for priority_queues.]

Common member functions for all STL containers Description
default constructor A constructor to provide a default initialization of the container. Nor-mally, each container has several constructors that provide different initialization methods for the container.
copy constructor A constructor that initializes the container to be a copy of an existing container of the same type.
destructor Destructor function for cleanup after a container is no longer needed.
empty Returns true if there are no elements in the container; otherwise, returns false.
size Returns the number of elements currently in the container.
operator= Assigns one container to another.
operator< Returns true if the first container is less than the second container; otherwise, returns false.
operator<= Returns true if the first container is less than or equal to the second container; otherwise, returns false.
operator> Returns true if the first container is greater than the second con-tainer; otherwise, returns false.
operator>= Returns true if the first container is greater than or equal to the sec-ond container; otherwise, returns false.
operator== Returns true if the first container is equal to the second container; otherwise, returns false.
operator!= Returns true if the first container is not equal to the second con-tainer; otherwise, returns false.
swap Swaps the elements of two containers.
Functions found only in first-class containers
max_size Returns the maximum number of elements for a container.
begin The two versions of this function return either an iterator or a const_iterator that refers to the first element of the container.
end The two versions of this function return either an iterator or a const_iterator that refers to the next position after the end of the container.
rbegin The two versions of this function return either a reverse_iterator or a const_reverse_iterator that refers to the last element of the container.
rend The two versions of this function return either a reverse_iterator or a const_reverse_iterator that refers to the next position after the last element of the reversed container.
erase Erases one or more elements from the container.
clear Erases all elements from the container.

Fig. 23.2 STL container common functions.

Page 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12

Tutorial Index