📄 map.html
字号:
such that <CODE>X.<A HREF="utility.html#pair::first">first</A> ==<A HREF="#map::lower_bound">lower_bound</A>(keyval)</CODE>and <CODE>X.<A HREF="utility.html#pair::second">second</A> ==<A HREF="#map::upper_bound">upper_bound</A>(keyval)</CODE>.</P><H3><CODE><A NAME="map::erase">map::erase</A></CODE></H3><PRE>iterator <B>erase</B>(iterator where);iterator <B>erase</B>(iterator first, iterator last);size_type <B>erase</B>(const Key& keyval);</PRE><P>The first member function removes the element of the controlledsequence pointed to by <CODE>where</CODE>.The second member function removes the elementsin the interval <CODE>[first, last)</CODE>.Both return an iterator that designates the first element remainingbeyond any elements removed, or<CODE><A HREF="#map::end">end</A>()</CODE> if no such element exists.</P><P>The third member function removesthe elements with sort keys in the range<CODE>[<A HREF="#map::lower_bound">lower_bound</A>(keyval),<A HREF="#map::upper_bound">upper_bound</A>(keyval)).</CODE>It returns the number of elements it removes.</P><P>The member functions never throw an exception.</P><H3><CODE><A NAME="map::find">map::find</A></CODE></H3><PRE>iterator <B>find</B>(const Key& keyval);const_iterator <B>find</B>(const Key& keyval) const;</PRE><P>The member function returns an iterator that designatesthe element in the controlled sequence whose sort key has<A HREF="lib_stl.html#equivalent ordering">equivalent ordering</A>to <CODE>keyval</CODE>. If no such element exists,the function returns<CODE><A HREF="#map::end">end</A>()</CODE>.</P><H3><CODE><A NAME="map::get_allocator">map::get_allocator</A></CODE></H3><PRE>Alloc <B>get_allocator</B>() const;</PRE><P>The member function returns the stored<A HREF="memory.html#allocator object">allocator object</A>.</P><H3><CODE><A NAME="map::insert">map::insert</A></CODE></H3><PRE>pair<iterator, bool> <B>insert</B>(const value_type& val);iterator <B>insert</B>(iterator where, const value_type& val);template<class InIt> void <B>insert</B>(InIt first, InIt last);</PRE><P>The first member function determines whether an element <CODE>X</CODE>exists in the sequence whose key has<A HREF="lib_stl.html#equivalent ordering">equivalent ordering</A>to that of <CODE>val</CODE>. If not, it creates suchan element <CODE>X</CODE> and initializes it with <CODE>val</CODE>.The function then determines the iterator <CODE>where</CODE> thatdesignates <CODE>X</CODE>. If an insertion occurred, the functionreturns <CODE><A HREF="utility.html#pair">pair</A>(where, true)</CODE>.Otherwise, it returns <CODE>pair(where, false)</CODE>.</P><P>The second member function returns <CODE>insert(val).first</CODE>,using <CODE>where</CODE> as a starting place within the controlledsequence to search for the insertion point. (Insertion can occurin amortized constant time, instead of logarithmic time, if theinsertion point immediately precedes or follows <CODE>where</CODE>.)The third member functioninserts the sequence of element values,for each <CODE>where</CODE> in the range <CODE>[first, last)</CODE>,by calling <CODE>insert(*where)</CODE>.</P><P>If an exception is thrown during theinsertion of a single element, the container is left unalteredand the exception is rethrown.If an exception is thrown during theinsertion of multiple elements, the container is left in a stablebut unspecified state and the exception is rethrown.</P><H3><CODE><A NAME="map::iterator">map::iterator</A></CODE></H3><PRE>typedef T0 <B>iterator</B>;</PRE><P>The type describes an object that can serve as a bidirectionaliterator for the controlled sequence.It is described here as asynonym for the implementation-defined type <CODE>T0</CODE>.</P><H3><CODE><A NAME="map::key_comp">map::key_comp</A></CODE></H3><PRE>key_compare <B>key_comp</B>() const;</PRE><P>The member function returns the stored function object thatdetermines the order of elements in the controlled sequence.The stored object defines the member function:</P><PRE>bool operator()(const Key& left, const Key& right);</PRE><P>which returns true if <CODE>left</CODE> strictlyprecedes <CODE>right</CODE> in the sort order.</P><H3><CODE><A NAME="map::key_compare">map::key_compare</A></CODE></H3><PRE>typedef Pr <B>key_compare</B>;</PRE><P>The type describes a function object that can compare twosort keys to determine the relative order of twoelements in the controlled sequence.</P><H3><CODE><A NAME="map::key_type">map::key_type</A></CODE></H3><PRE>typedef Key <B>key_type</B>;</PRE><P>The type describes the sort key object stored in eachelement of the controlled sequence.</P><H3><CODE><A NAME="map::lower_bound">map::lower_bound</A></CODE></H3><PRE>iterator <B>lower_bound</B>(const Key& keyval);const_iterator <B>lower_bound</B>(const Key& keyval) const;</PRE><P>The member function returns an iterator that designates theearliest element <CODE>X</CODE> in the controlled sequence for which<CODE><A HREF="#map::key_comp">key_comp</A>()(X.<A HREF="utility.html#pair::first">first</A>, keyval)</CODE> isfalse.</P> If no such element exists, the function returns<CODE><A HREF="#map::end">end</A>()</CODE>.<H3><CODE><A NAME="map::map">map::map</A></CODE></H3><PRE><B>map</B>();explicit <B>map</B>(const Pr& pred);<B>map</B>(const Pr& pred, const Alloc& al);<B>map</B>(const map& right);template<class InIt> <B>map</B>(InIt first, InIt last);template<class InIt> <B>map</B>(InIt first, InIt last, const Pr& pred);template<class InIt> <B>map</B>(InIt first, InIt last, const Pr& pred, const Alloc& al);</PRE><P>All constructors store an<A HREF="memory.html#allocator object">allocator object</A> andinitialize the controlled sequence. The allocator object is the argument<CODE>al</CODE>, if present. For the copy constructor, it is<CODE>right.<A HREF="#map::get_allocator">get_allocator</A>()</CODE>.Otherwise, it is <CODE>Alloc()</CODE>.</P><P>All constructors also store a function object that can laterbe returned by calling<CODE><A HREF="#map::key_comp">key_comp</A>()</CODE>.The function object is the argument <CODE>pred</CODE>, if present.For the copy constructor, it is<CODE>right.<A HREF="#map::key_comp">key_comp</A>()</CODE>).Otherwise, it is <CODE>Pr()</CODE>.</P><P>The first three constructors specify anempty initial controlled sequence. The fourth constructor specifiesa copy of the sequence controlled by <CODE>right</CODE>.The last three constructors specify the sequence of element values<CODE>[first, last)</CODE>.</P><H3><CODE><A NAME="map::mapped_type">map::mapped_type</A></CODE></H3><PRE>typedef Ty <B>mapped_type</B>;</PRE><P>The type is a synonym for the template parameter <CODE>Ty</CODE>.</P><H3><CODE><A NAME="map::max_size">map::max_size</A></CODE></H3><PRE>size_type <B>max_size</B>() const;</PRE><P>The member function returns the length of the longest sequence thatthe object can control.</P><H3><CODE><A NAME="map::operator[]">map::operator[]</A></CODE></H3><PRE>Ty& <B>operator[]</B>(const Key& keyval);</PRE><P>The member function effectively determines the iterator <CODE>where</CODE>as the return value of<CODE><A HREF="#map::insert">insert</A>(<A HREF="#map::value_type">value_type</A>(keyval, Ty())</CODE>.(It inserts an element with the specified key if no such elementexists.) It then returns a reference to<CODE>(*where).<A HREF="utility.html#pair::second">second</A></CODE>.</P><H3><CODE><A NAME="map::pointer">map::pointer</A></CODE></H3><PRE>typedef Alloc::pointer <B>pointer</B>;</PRE><P>The type describes an object that can serve as a pointer to anelement of the controlled sequence.</P><H3><CODE><A NAME="map::rbegin">map::rbegin</A></CODE></H3><PRE>const_reverse_iterator <B>rbegin</B>() const;reverse_iterator <B>rbegin</B>();</PRE><P>The member function returns a reverse bidirectionaliterator that points justbeyond the end of the controlled sequence. Hence, it designates thebeginning of the reverse sequence.</P><H3><CODE><A NAME="map::reference">map::reference</A></CODE></H3><PRE>typedef Alloc::reference <B>reference</B>;</PRE><P>The type describes an object that can serve as a reference to anelement of the controlled sequence.</P><H3><CODE><A NAME="map::rend">map::rend</A></CODE></H3><PRE>const_reverse_iterator <B>rend</B>() const;reverse_iterator <B>rend</B>();</PRE><P>The member function returns a reverse bidirectionaliterator that points at thefirst element of the sequence (or just beyond the end of an emptysequence). Hence, it designates the end of the reverse sequence.</P><H3><CODE><A NAME="map::reverse_iterator">map::reverse_iterator</A></CODE></H3><PRE>typedef reverse_iterator<iterator> <B>reverse_iterator</B>;</PRE><P>The type describes an object that can serve as a reversebidirectional iterator for the controlled sequence.</P><H3><CODE><A NAME="map::size">map::size</A></CODE></H3><PRE>size_type <B>size</B>() const;</PRE><P>The member function returns the length of the controlled sequence.</P><H3><CODE><A NAME="map::size_type">map::size_type</A></CODE></H3><PRE>typedef T2 <B>size_type</B>;</PRE><P>The unsigned integer type describes an object that can represent thelength of any controlled sequence. It is described here as asynonym for the implementation-defined type <CODE>T2</CODE>.</P><H3><CODE><A NAME="map::swap">map::swap</A></CODE></H3><PRE>void <B>swap</B>(map& right);</PRE><P>The member function swaps the controlled sequences between<CODE>*this</CODE> and <CODE>right</CODE>. If<CODE><A HREF="#map::get_allocator">get_allocator</A>()== right.get_allocator()</CODE>, it does so in constant time,it throws an exception only as a result of copying the storedfunction object of type <CODE>Pr</CODE>, and it invalidates no references, pointers,or iterators that designate elements in the two controlled sequences.Otherwise, it performs a number of element assignments and constructor callsproportional to the number of elements in the two controlled sequences.</P><H3><CODE><A NAME="map::upper_bound">map::upper_bound</A></CODE></H3><PRE>iterator <B>upper_bound</B>(const Key& keyval);const_iterator <B>upper_bound</B>(const Key& keyval) const;</PRE><P>The member function returns an iterator that designates theearliest element <CODE>X</CODE> in the controlled sequence for which<CODE><A HREF="#map::key_comp">key_comp</A>()(keyval,X.<A HREF="utility.html#pair::first">first</A>)</CODE> istrue.</P> If no such element exists, the function returns<CODE><A HREF="#map::end">end</A>()</CODE>.<H3><CODE><A NAME="map::value_comp">map::value_comp</A></CODE></H3><PRE>value_compare <B>value_comp</B>() const;</PRE><P>The member function returns a function object thatdetermines the order of elements in the controlled sequence.</P><H3><CODE><A NAME="map::value_compare">map::value_compare</A></CODE></H3><PRE>class <B>value_compare</B> : public <A HREF="functio2.html#binary_function">binary_function</A><value_type, value_type, bool> {public: bool operator()(const value_type& left, const value_type& right) const {return (comp(left.first, right.first)); }protected: value_compare(key_compare pr) : comp(pr) {} key_compare comp; };</PRE><P>The type describes a function object that can compare thesort keys in two elements to determine their relative orderin the controlled sequence. The function object stores an object<B><CODE><A NAME="map::value_compare::comp">comp</A></CODE></B>of type <CODE><A HREF="#map::key_compare">key_compare</A></CODE>.The member function <B><CODE>operator()</CODE></B> uses thisobject to compare the sort-key components of two element.</P><H3><CODE><A NAME="map::value_type">map::value_type</A></CODE></H3><PRE>typedef <A HREF="utility.html#pair">pair</A><const Key, Ty> <B>value_type</B>;</PRE><P>The type describes an element of the controlled sequence.</P><H2><A NAME="multimap"><CODE>multimap</CODE></A></H2><HR><P><B><CODE><A HREF="#multimap::allocator_type">allocator_type</A>· <A HREF="#multimap::begin">begin</A>· <A HREF="#multimap::clear">clear</A>· <A HREF="#multimap::const_iterator">const_iterator</A>· <A HREF="#multimap::const_pointer">const_pointer</A>· <A HREF="#multimap::const_reference">const_reference</A>· <A HREF="#multimap::const_reverse_iterator">const_reverse_iterator</A>· <A HREF="#multimap::count">count</A>· <A HREF="#multimap::difference_type">difference_type</A>· <A HREF="#multimap::empty">empty</A>· <A HREF="#multimap::end">end</A>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -