⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 associativecontainer.html

📁 Standard Template Library (SOURCE + COMPLETE html man document)
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<h3>Expression semantics</h3><Table border><TR><TH>Name</TH><TH>Expression</TH><TH>Precondition</TH><TH>Semantics</TH><TH>Postcondition</TH></TR><TR><TD VAlign=top>Default constructor</TD><TD VAlign=top><pre>X()X a;</pre></TD><TD VAlign=top>&nbsp;</TD><TD VAlign=top>Creates an empty container.</TD><TD VAlign=top>The size of the container is <tt>0</tt>.</TD></TR><TR><TD VAlign=top>Erase key</TD><TD VAlign=top><tt>a.erase(k)</tt></TD><TD VAlign=top>&nbsp;</TD><TD VAlign=top>Destroys all elements whose key is the same as <tt>k</tt>, and removes   them from <tt>a</tt>. <A href="#2">[2]</A>  The return value is the number of elements that   were erased, <i>i.e.</i> the old value of <tt>a.count(k)</tt>.</TD><TD VAlign=top><tt>a.size()</tt> is decremented by <tt>a.count(k)</tt>.   <tt>a</tt> contains no elements with key <tt>k</tt>.  </TD></TR><TR><TD VAlign=top>Erase element</TD><TD VAlign=top><tt>a.erase(p)</tt></TD><TD VAlign=top><tt>p</tt> is a dereferenceable iterator in <tt>a</tt>.</TD><TD VAlign=top>Destroys the element pointed to by <tt>p</tt>, and removes it from <tt>a</tt>.</TD><TD VAlign=top><tt>a.size()</tt> is decremented by 1.</TD></TR><TR><TD VAlign=top>Erase range</TD><TD VAlign=top><tt>a.erase(p, q)</tt></TD><TD VAlign=top><tt>[p, q)</tt> is a valid range in <tt>a</tt>.</TD><TD VAlign=top>Destroys the elements in the range <tt>[p,q)</tt> and removes them from   <tt>a</tt>. </TD><TD VAlign=top><tt>a.size()</tt> is decremented by the distance from <tt>i</tt> to <tt>j</tt>.</TD></TR><TR><TD VAlign=top>Clear</TD><TD VAlign=top><tt>a.clear()</tt></TD><TD VAlign=top>&nbsp;</TD><TD VAlign=top>Equivalent to <tt>a.erase(a.begin(), a.end())</tt></TD><TD VAlign=top>&nbsp;</TD></TR><TR><TD VAlign=top>Find</TD><TD VAlign=top><tt>a.find(k)</tt></TD><TD VAlign=top>&nbsp;</TD><TD VAlign=top>Returns an iterator pointing to an element whose key is the same   as <tt>k</tt>, or <tt>a.end()</tt> if no such element exists.</TD><TD VAlign=top>Either the return value is <tt>a.end()</tt>, or else the return value has   a key that is the same as <tt>k</tt>.</TD></TR><TR><TD VAlign=top>Count</TD><TD VAlign=top><tt>a.count(k)</tt></TD><TD VAlign=top>&nbsp;</TD><TD VAlign=top>Returns the number of elements in <tt>a</tt> whose keys are the same as <tt>k</tt>.</TD><TD VAlign=top>&nbsp;</TD></TR><TR><TD VAlign=top>Equal range</TD><TD VAlign=top><tt>a.equal_range(k)</tt></TD><TD VAlign=top>&nbsp;</TD><TD VAlign=top>Returns a pair <tt>P</tt> such that <tt>[P.first, P.second)</tt> is a range   containing all elements in <tt>a</tt> whose keys are the same as <tt>k</tt>. <A href="#3">[3]</A>   If no elements have the same key as <tt>k</tt>, the return value is an empty   range.</TD><TD VAlign=top>The distance between <tt>P.first</tt> and <tt>P.second</tt> is equal to   <tt>a.count(k)</tt>.  If <tt>p</tt> is a dereferenceable iterator in <tt>a</tt>, then   either <tt>p</tt> lies in the range <tt>[P.first, P.second)</tt>, or else   <tt>*p</tt> has a key that is not the same as <tt>k</tt>.</TD></tr></table><h3>Complexity guarantees</h3>Average complexity for erase key is at most <tt>O(log(size()) + count(k))</tt>.<P>Average complexity for erase element is constant time.<P>Average complexity for erase range is at most    <tt>O(log(size()) + N)</tt>, where <tt>N</tt> is the number of elements in the range.<P>Average complexity for count is at most <tt>O(log(size()) + count(k))</tt>.<P>Average complexity for find is at most logarithmic.<P>Average complexity for equal range is at most logarithmic.<h3>Invariants</h3><Table border><TR><TD VAlign=top>Contiguous storage</TD><TD VAlign=top>All elements with the same key are adjacent to each other.  That   is, if <tt>p</tt> and <tt>q</tt> are iterators that point to elements that have   the same key, and if <tt>p</tt> precedes <tt>q</tt>, then every element in the   range <tt>[p, q)</tt> has the same key as every other element.</TD></TR><TR><TD VAlign=top>Immutability of keys</TD><TD VAlign=top>Every element of an Associative Container has an immutable key.   Objects may be inserted and erased, but an element in an    Associative Container may not be modified in such a way as to change   its key.</TD></tr></table><h3>Models</h3><UL><LI><tt><A href="set.html">set</A></tt><LI><tt><A href="multiset.html">multiset</A></tt><LI><tt><A href="hash_set.html">hash_set</A></tt><LI><tt><A href="hash_multiset.html">hash_multiset</A></tt><LI><tt><A href="Map.html">map</A></tt><LI><tt><A href="Multimap.html">multimap</A></tt><LI><tt><A href="hash_map.html">hash_map</A></tt><LI><tt><A href="hash_multimap.html">hash_multimap</A></tt></UL><h3>Notes</h3><P><A name="1">[1]</A>The reason there is no such mechanism is that the way in whichelements are arranged in an associative container is typically a classinvariant; elements in a <A href="SortedAssociativeContainer.html">Sorted Associative Container</A>, forexample, are always stored in ascending order, and elements in a <A href="HashedAssociativeContainer.html">Hashed Associative Container</A> are always stored according to thehash function.  It would make no sense to allow the position of anelement to be chosen arbitrarily.<P><A name="2">[2]</A>Keys are not required to be <A href="EqualityComparable.html">Equality Comparable</A>: associativecontainers do not necessarily use <tt>operator==</tt> to determine whether twokeys are the same.  In <A href="SortedAssociativeContainer.html">Sorted Associative Containers</A>, for example,where keys are ordered by a comparison function, two keys are consideredto be the same if neither one is less than the other.<P><A name="3">[3]</A>Note the implications of this member function: it means that iftwo elements have the same key, there must be no elements withdifferent keys in between them.  The requirement that elements withthe same key be stored contiguously is an associative containerinvariant.<h3>See also</h3><A href="SimpleAssociativeContainer.html">Simple Associative Container</A>, <A href="PairAssociativeContainer.html">Pair Associative Container</A>,<A href="UniqueAssociativeContainer.html">Unique Associative Container</A>, <A href="MultipleAssociativeContainer.html">Multiple Associative Container</A>,<A href="SortedAssociativeContainer.html">Sorted Associative Container</A>, <A href="UniqueSortedAssociativeContainer.html">Unique Sorted Associative Container</A>, <A href="MultipleSortedAssociativeContainer.html">Multiple Sorted Associative Container</A>,<A href="HashedAssociativeContainer.html">Hashed Associative Container</A>,<A href="UniqueHashedAssociativeContainer.html">Unique Hashed Associative Container</A>, <A href="MultipleHashedAssociativeContainer.html">Multiple Hashed Associative Container</A>.<!-- start footer --><!-- Footer Begins --><STYLE TYPE="text/css"><!--TD.footer, TD.footer A{		font-family: Arial, helvetica, sans-serif;        	font-size: 8pt;}A.home {font-family: Arial, helvetica, sans-serif;}--></STYLE><P><A CLASS="home" HREF="index.html">STL Home</A><P><TABLE WIDTH="600" CELLPADDING="0" CELLPADDING="0" BORDER="0">	<TR>	    <TD ALIGN="RIGHT" CLASS="footer"><A HREF="/company_info/terms.html" TARGET="_top">terms of use</A> | <A HREF="/company_info/privacy.html" TARGET="_top">privacy policy</A></TD>	    <TD ALIGN="CENTER" CLASS="footer">&nbsp;|&nbsp;</TD>	    <TD ALIGN="LEFT" CLASS="footer"><A HREF="/cgi-bin/feedback/" TARGET="_top">contact us</A></TD>	</TR><TR>	    <TD ALIGN="RIGHT" CLASS="footer">Copyright &copy; 1993-2003 Silicon Graphics, Inc. All rights reserved.</TD>	    <TD ALIGN="CENTER" CLASS="footer">&nbsp;|&nbsp;</TD>	    <TD ALIGN="LEFT" CLASS="footer"><A HREF="/company_info/trademarks/" TARGET="_top">Trademark Information</A></TD>	</TR></TABLE><!-- Footer Ends --><!-- end footer --><P></BODY></HTML> 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -