📄 map_8018.htm
字号:
<HTML><TITLE>map </TITLE><BODY>
<A HREF="ref.htm"><IMG SRC="images/banner.gif"></A>
<P><STRONG>Click on the banner to return to the Class Reference home page.</STRONG></P>
<P>©Copyright 1996 Rogue Wave Software</P>
<H2>map </H2>
<HR><PRE> Container</PRE><HR>
<A NAME="Summary"><H3>Summary</H3></A>
<P>An associative container providing access to non-key values using unique keys. A <B><I>map</B></I> supports bidirectional iterators.</P>
<H3>Contents</H3>
<UL>
<A HREF="#Synopsis"><LI>Synopsis</LI></A>
<A HREF="#Description"><LI>Description</LI></A>
<A HREF="#Interface"><LI>Interface</LI></A>
<A HREF="#Constructors and Destructors"><LI>Constructors and Destructors</LI></A>
<A HREF="#Allocator"><LI>Allocator</LI></A>
<A HREF="#Iterators"><LI>Iterators</LI></A>
<A HREF="#Member Operators"><LI>Member Operators</LI></A>
<A HREF="#Allocator"><LI>Allocator</LI></A>
<A HREF="#Member Functions"><LI>Member Functions</LI></A>
<A HREF="#Non-member Operators"><LI>Non-member Operators</LI></A>
<A HREF="#Example"><LI>Example</LI></A>
<A HREF="#Warning"><LI>Warning</LI></A>
<A HREF="#See Also"><LI>See Also</LI></A>
</UL>
<A NAME="Synopsis"><H3>Synopsis</H3></A>
<PRE>#include <map></PRE>
<PRE>
template <class Key, class T, class Compare = less<Key>
class Allocator = allocator>
class <B>map</B>;</PRE>
<A NAME="Description"><H3>Description</H3></A>
<P><B><I>map <Key, T, Compare, Allocator></B></I> provides fast access to stored values of type <SAMP>T</SAMP> which are indexed by unique keys of type <B><I>Key</B></I>. The default operation for key comparison is the <SAMP><</SAMP> operator. </P>
<P><B><I>map</B></I> provides bidirectional iterators that point to an instance of <SAMP>pair<const Key x, T y></SAMP> where <SAMP>x</SAMP> is the key and <SAMP>y</SAMP> is the stored value associated with that key. The definition of <B><I>map</B></I> provides a <SAMP>typedef</SAMP> to this pair called <SAMP>value_type</SAMP>. </P>
<P>The types used for both the template parameters <SAMP>Key</SAMP> and<SAMP> T</SAMP> must provide the following (where <SAMP>T</SAMP> is the <SAMP>type</SAMP>, <SAMP>t</SAMP> is a <SAMP>value</SAMP> of <SAMP>T</SAMP> and <SAMP>u</SAMP> is a <SAMP>const</SAMP> <SAMP>value</SAMP> of <SAMP>T</SAMP>): </P>
<PRE> Copy constructors - T(t) and T(u)
Destructor - t.~T()
Address of - &t and &u yielding T* and
const T* respectively
Assignment - t = a where a is a
(possibley const) value of T
</PRE><P>The type used for the <SAMP>Compare</SAMP> template parameter must satisfy the requirements for binary functions. </P>
<A NAME="Interface"><H3>Interface</H3></A>
<PRE>template <class Key, class T, class Compare = less<Key>
class Allocator = allocator, >
class map {
public:
// types
typedef Key key_type;
typedef T mapped_type;
typedef pair<const Key, T> value_type;
typedef Compare key_compare;
typedef Allocator allocator_type;
typename reference;
typename const_reference;
typename iterator;
typename const_iterator;
typename size_type;
typename difference_type;
typename reverse_iterator;
typename const_reverse_iterator;
class value_compare
: public binary_function<value_type, value_type, bool>
{
friend class map<Key, T, Compare, Allocator>;
public :
bool operator() (const value_type&,
const value_type&) const;
};
// Construct/Copy/Destroy
explicit map (const Compare& = Compare(),
const Allocator& = Allocator ());
template <class InputIterator>
map (InputIterator, InputIterator,
const Compare& = Compare(),
const Allocator& = Allocator ());
map (const map<Key, T, Compare, Allocator>&);
~map();
map<Key, T, Compare, Allocator>&
operator= (const map<Key, T, Compare, Allocator>&);
allocator_type get_allocator () const;
// Iterators
iterator begin();
const_iterator begin() const;
iterator end();
const_iterator end() const;
reverse_iterator rbegin();
const_reverse_iterator rbegin() const;
reverse_iterator rend();
const_reverse_iterator rend() const;
// Capacity
bool empty() const;
size_type size() const;
size_type max_size() const;
// Element Access
mapped_type& operator[] (const key_type&);
const mapped_type& operator[] (const key_type&) const;
// Modifiers
pair<iterator, bool> insert (const value_type&);
iterator insert (iterator, const value_type&);
template <class InputIterator>
void insert (InputIterator, InputIterator);
iterator erase (iterator);
size_type erase (const key_type&);
iterator erase (iterator, iterator);
void swap (map<Key, T, Compare, Allocator>&);
// Observers
key_compare key_comp() const;
value_compare value_comp() const;
// Map operations
iterator find (const key_value&);
const_iterator find (const key_value&) const;
size_type count (const key_type&) const;
iterator lower_bound (const key_type&);
const_iterator lower_bound (const key_type&) const;
iterator upper_bound (const key_type&);
const_iterator upper_bound (const key_type&) const;
pair<iterator, iterator> equal_range (const key_type&);
pair<const_iterator, const_iterator>
equal_range (const key_type&) const;
};
// Non-member Map Operators
template <class Key, class T, class Compare, class Allocator>
<SAMP>bool</SAMP> operator== (const map<Key, T, Compare, Allocator>&,
const map<Key, T, Compare, Allocator>&);
template <class Key, class T, class Compare, class Allocator>
bool <B>operator<</B> (const map<Key, T, Compare, Allocator>&,
const map<Key, T, Compare, Allocator>&);
// Specialized Algorithms
template <class Key, class T, class Compare, class Allocator>
void <B>swap</B> (map<Key,T,Compare,Allocator>&,
map<Key,T,Compare,Allocator>&);
</PRE>
<A NAME="Constructors and Destructors"><H3>Constructors and Destructors</H3></A>
<PRE>explicit <B>map</B> (const Compare& comp = Compare (),
const Allocator& alloc = Allocator());</PRE>
<UL><P>Default constructor. Constructs an empty map that will use the relation <SAMP>comp</SAMP> to order keys, if it is supplied. The map will use the allocator <SAMP>alloc</SAMP> for all storage management.</P>
</UL>
<PRE>template <class InputIterator>
<B>map</B> (InputIterator first, InputIterator last,
const Compare& comp = Compare (),
const Allocator& alloc = Allocator());</PRE>
<UL><P>Constructs a map containing values in the range <SAMP>[first, last)</SAMP>. Creation of the new map is only guaranteed to succeed if the iterators <SAMP>first</SAMP> and <SAMP>last</SAMP> return values of type <SAMP>pair<class Key, class Value></SAMP> and all values of <SAMP>Key</SAMP> in the <SAMP>range[first, last)</SAMP> are unique. The map will use the relation <SAMP>comp</SAMP> to order keys, and the allocator <SAMP>alloc</SAMP> for all storage management.</P>
</UL>
<PRE><B>map</B> (const map<Key,T,Compare,Allocator>& x);</PRE>
<UL><P>Copy constructor. Creates a new map by copying all pairs of <SAMP>key</SAMP> and <SAMP>value</SAMP> from <SAMP>x</SAMP>. </P>
</UL>
<PRE>~<B>map</B> ();</PRE>
<UL><P>The destructor. Releases any allocated memory for this map.</P>
</UL>
<A NAME="Allocator"><H3>Allocator</H3></A>
<PRE>allocator_type <B>get_allocator</B> () const;</PRE>
<UL><P>Returns a copy of the allocator used by self for storage management.</P>
</UL>
<A NAME="Iterators"><H3>Iterators</H3></A>
<PRE>iterator <B>begin</B>() ;</PRE>
<UL><P>Returns an <SAMP>iterator</SAMP> pointing to the first element stored in the map. "First" is defined by the map's comparison operator, <SAMP>Compare</SAMP>. </P>
</UL>
<PRE>const_iterator <B>begin</B>() const;</PRE>
<UL><P>Returns a <SAMP>const_iterator</SAMP> pointing to the first element stored in the map. </P>
</UL>
<PRE>iterator <B>end</B>() ;</PRE>
<UL><P>Returns an <SAMP>iterator</SAMP> pointing to the last element stored in the map, i.e., the off-the-end value. </P>
</UL>
<PRE>const_iterator <B>end</B>() const;</PRE>
<UL><P>Returns a <SAMP>const_iterator</SAMP> pointing to the last element stored in the map. </P>
</UL>
<PRE>reverse_iterator <B>rbegin</B>();</PRE>
<UL><P>Returns a <SAMP>reverse_iterator</SAMP> pointing to the first element stored in the map. "First" is defined by the map's comparison operator, <SAMP>Compare</SAMP>. </P>
</UL>
<PRE>const_reverse_iterator <B>rbegin</B>() const;</PRE>
<UL><P>Returns a <SAMP>const_reverse_iterator</SAMP> pointing to the first element stored in the map. </P>
</UL>
<PRE>reverse_iterator <B>rend</B>() ;</PRE>
<UL><P>Returns a <SAMP>reverse_iterator </SAMP>pointing to the last element stored in the map, i.e., the off-the-end value.</P>
</UL>
<PRE>const_reverse_iterator <B>rend</B>() const;</PRE>
<UL><P>Returns a <SAMP>const_reverse_iterator</SAMP> pointing to the last element stored in the map</P>
</UL>
<A NAME="Member Operators"><H3>Member Operators</H3></A>
<PRE>map<Key, T, Compare, Allocator>&
<B>operator= </B>(const map<Key, T, Compare, Allocator>& x);</PRE>
<UL><P>Assignment. Replaces the contents of <SAMP>*this</SAMP> with a copy of the map <SAMP>x</SAMP>. </P>
</UL>
<PRE>mapped_type& <B>operator[]</B> (const key_type& x);</PRE>
<UL><P>If an element with the key <SAMP>x</SAMP> exists in the map, then a reference to its associated value will be returned. Otherwise the pair <SAMP>x,T() </SAMP>will be inserted into the map and a reference to the default object <SAMP>T()</SAMP> will be returned. </P>
</UL>
<A NAME="Allocator"><H3>Allocator</H3></A>
<PRE>allocator_type <B>get_allocator</B> () const;</PRE>
<UL><P>Returns a copy of the allocator used by self for storage management.</P>
</UL>
<A NAME="Member Functions"><H3>Member Functions</H3></A>
<PRE>void
<B>clear</B> ();</PRE>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -