map
|
 |
An associative container that
manages a set of ordered key/value pairs. The pairs are ordered by key, based on
a user-supplied comparator function. Only one value can be associated with a
particular key. You can efficiently find this value due to map
's underlying data structure.
Library
Standards<ToolKit>
Declaration
#include <map>
template< class Key, class Value, class Compare, class Allocator >
class map
Interface
Constructor
map()
Constructs an empty map
that orders its keys using the compare function specified when the map
template was instantiated.
Constructor
explicit
map( const Compare& comp ,
const Allocator& alloc )
Constructs an empty map
that orders its keys using the comparator comp ,
and uses alloc (default Allocator
()) to manage storage.
Constructor
map(
const value_type* first ,
const value_type* last ,
const Compare& comp ,
const Allocator& alloc )
Constructs a map that
contains copies of the key/value pairs in the range [
first , last
) , using the comparator comp
(default Compare() ) to order the keys. Uses
the allocator alloc (default Allocator()
) to manage storage.
Constructor
map(
const_iterator first ,
const_iterator last ,
const Compare& comp ,
const Allocator& alloc )
Constructs a map that
contains copies of the key/value pairs in the range [
first , last
) , using the comparator comp
(default Compare() ) to order the keys. Uses
the allocator alloc (default Allocator()
) to manage storage.
Constructor
map(
const map< Key, Value, Compare, Allocator >& other
)
Constructs a copy of other
.
Destructor
~map()
Destroys the map and
erases all of its key/value pairs.
=
map<
Key, Value, Compare, Allocator >& operator=( const map< Key,
Value, Compare, Allocator >& other )
Replaces the map's
contents with other .
[]
Value&
operator []( const Key& key )
If no value is associated
with key , associates key
with a default-constructed value and returns a reference to this new value.
Otherwise, returns a reference to the value already associated with key
.
begin
iterator
begin()
Returns an iterator
positioned at map's first key/value pair.
begin
const_iterator
begin() const
Returns an iterator
positioned at map's first key/value pair.
clear
void
clear()
Erases all of map's
key/value pairs.
count
size_type
count( const Key& key )
const
Returns the number of
key/value pairs map contains with a key that matches key
.
empty
bool
empty() const
Returns true
if map contains no entries.
end
iterator
end()
Returns an iterator
positioned immediately after map's last key/value pair.
end
const_iterator
end() const
Returns an iterator
positioned immediately after map's last key/value pair.
equal_range
pair<
iterator, iterator > equal_range( const Key& key )
Returns a pair of
iterators with first element equal to lower_bound()
and second element equal to upper_bound() .
equal_range
pair<
const_iterator, const_iterator > equal_range( const Key& key ) const
Returns a pair of
iterators with first element equal to lower_bound()
and second element equal to upper_bound() .
erase
void
erase( iterator pos )
Erases the key/value pair
at pos .
erase
void
erase( iterator first ,
iterator last )
Erases the key/value pairs
in range [ first ,
last ) .
erase
size_type
erase( const Key& key )
Erases all key/value pairs
with a key that matches key and returns the number
of elements erased.
find
iterator
find( const Key& key )
If map contains a
key/value pair with a key that matches key ,
returns an iterator positioned at the matching pair. Otherwise, returns an
iterator positioned at end() .
find
const_iterator
find( const Key& key )
const
If map contains a
key/value pair with a key that matches key ,
returns a constant iterator positioned at the matching pair. Otherwise,
returns a constant iterator positioned at end()
.
get_allocator
Allocator
get_allocator() const
Returns a copy of the
allocator that map is using to manage storage.
insert
pair<
iterator, bool > insert( const value_type& pair
)
If map does not contain a
key/value pair with a key that matches that of pair
, inserts a copy of pair and returns a pair with a
first element that is an iterator positioned at the new key/value pair and a
second element that is true . If map already
contains a key/value pair with a key that matches that of pair
, returns a pair with a first element that is an iterator positioned at the
existing key/value pair and a second element that is false
.
insert
void
insert( const value_type* first ,
const value_type*
last )
Inserts copies of the
key/value pairs in the range [ first
, last ) .
insert
void
insert( const_iterator first ,
const_iterator last )
Inserts copies of the
key/value pairs in the range [ first
, last ) .
insert
iterator
insert( iterator pos ,
const value_type& pair )
Inserts a copy of pair
if map does not contain an key/value pair with a key that matches its key,
using pos as a hint on where to start searching
for the correct place to insert.
insert
pair<
iterator, bool > insert( const Key& key
, const Value& value )
If map does not contain a
key that matches key , inserts the new key/value
pair, and returns a pair with a first element that is an iterator positioned
at the new key/value pair and a second element that is true
. If map already contains a key that matches key ,
returns a pair with a first element that is an iterator positioned at the
existing key/value pair and a second element that is false
. This is a non-standard extension unique to Standards<ToolKit>.
key_comp
Compare
key_comp() const
Returns the comparison
object used to compare map's keys.
lower_bound
iterator
lower_bound( const Key& key )
Returns an iterator
positioned at the first location a pair with key key
can be inserted without violating the ordering criteria. If no such location
is found, returns an iterator positioned at end()
.
lower_bound
const_iterator
lower_bound( const Key& key )
const
Returns an iterator
positioned at the first location a pair with key key
can be inserted without violating the ordering
criteria. If no such location is found, returns an iterator positioned at end()
.
max_size
size_type
max_size() const
Returns the maximum number
of key/value pairs that map can contain.
rbegin
reverse_iterator
rbegin()
Returns a reverse iterator
positioned at map's last key/value pair.
rbegin
const_reverse_iterator
rbegin() const
Returns a reverse iterator
positioned at map's last key/value pair.
rend
reverse_iterator
rend()
Returns a reverse iterator
positioned immediately before map's first key/value pair.
rend
const_reverse_iterator
rend() const
Returns a reverse iterator
positioned immediately before map's first key/value pair.
size
size_type
size() const
Returns the number of
key/value pairs that map contains.
swap
void
swap( map< Key, Value, Compare, Allocator >& other
)
Exchanges the contents of
map and other .
upper_bound
iterator
upper_bound( const Key& key )
Returns an iterator
positioned at the last location a pair with key key
can be inserted without violating the ordering criteria. If no such location
is found, returns an iterator positioned at end()
.
upper_bound
const_iterator
upper_bound( const Key& key )
const
Returns an iterator
positioned at the last location a pair with key key
can be inserted without violating the ordering criteria. If no such location
is found, returns an iterator positioned at end()
.
value_comp
value_compare
value_comp() const
Returns the comparison
object used for comparing map's key/value pairs.
Non-Member Functions
==
bool
operator==( const map< Key, Value, Compare, Allocator >& x
, const map< Key, Value,
Compare, Allocator >& y )
const
Returns true
if x contains the same items in the same order as y
.
<
bool
operator<( const map< Key, Value, Compare, Allocator >& x
, const Map< Key, Value,
Compare, Allocator >& y )
const
Returns true
if x is lexicographically less than y.
swap
void swap
( map< Key, Value, Compare, Allocator >& x
, map< Key, Value, Compare,
Allocator >& y ) const
Exchanges the contents of
x and y .
Copyright©1994-2026 Recursion Software LLC
All Rights Reserved - For use by licensed users only.