Map and multimap operations, Declaration and initialization of map, Type definitions – HP Integrity NonStop H-Series User Manual
Page 98
![background image](/manuals/396950/98/background.png)
Click on the banner to return to the user guide home page.
©Copyright 1996 Rogue Wave Software
Map and Multimap Operations
The member functions provided by the map and multimap data types will shortly be described
in more detail. 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 map
The declaration of a map follows the pattern we have seen repeatedly in the standard library. A
map is a template data structure, specialized by the type of the key elements, the type of the
associated values, and the operator to be used in comparing keys. If your compiler supports
default template types (a relatively new feature in C++ not yet supported by all vendors), then
the last of these is optional, and if not provided, the less than operator for the key type will be
assumed. Maps can be declared with no initial elements, or initialized from another container by
providing a pair of iterators. In the latter case the iterators must denote values of type
pair
; the
first field in each pair is taken to be a key, while the second field is a value. A copy constructor
also permits maps to be created as copies of other maps.
// map indexed by doubles containing strings
map
// map indexed by integers, containing integers
map
// create a new map, initializing it from map two
map
A map can be assigned to another map, and two maps can exchange their values using the
swap() operation (in a manner analogous to other standard library containers).
Type Definitions
The classes
map
and
multimap
include a number of type definitions. These are most commonly
used in declaration statements. For example, an iterator for a map of strings to integers can be
declared in the following fashion:
map
In addition to iterator, the following types are defined: