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

📄 set.html

📁 Standard Template Library (SOURCE + COMPLETE html man document)
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<HTML><!--  -- Copyright (c) 1996-1999  -- Silicon Graphics Computer Systems, Inc.  --  -- Permission to use, copy, modify, distribute and sell this software  -- and its documentation for any purpose is hereby granted without fee,  -- provided that the above copyright notice appears in all copies and  -- that both that copyright notice and this permission notice appear  -- in supporting documentation.  Silicon Graphics makes no  -- representations about the suitability of this software for any  -- purpose.  It is provided "as is" without express or implied warranty.  --  -- Copyright (c) 1994  -- Hewlett-Packard Company  --  -- Permission to use, copy, modify, distribute and sell this software  -- and its documentation for any purpose is hereby granted without fee,  -- provided that the above copyright notice appears in all copies and  -- that both that copyright notice and this permission notice appear  -- in supporting documentation.  Hewlett-Packard Company makes no  -- representations about the suitability of this software for any  -- purpose.  It is provided "as is" without express or implied warranty.  --  --><Head><Title>set&lt;Key, Compare, Alloc&gt;</Title><!-- Generated by htmldoc --></HEAD><BODY TEXT="#000000" LINK="#006600" ALINK="#003300" VLINK="#7C7F87" BGCOLOR="#FFFFFF"><A HREF="/"><IMG SRC="/images/common/sgilogo_small.gif" ALT="SGI Logo" WIDTH="80" HEIGHT="72" BORDER="0"></A><P><!--end header--><BR Clear><H1>set&lt;Key, Compare, Alloc&gt;</H1><Table CellPadding=0 CellSpacing=0 width=100%><TR><TD Align=left><Img src = "containers.gif" Alt=""   WIDTH = "194"  HEIGHT = "38" ></TD><TD Align=right><Img src = "type.gif" Alt=""   WIDTH = "194"  HEIGHT = "38" ></TD></TR><TR><TD Align=left VAlign=top><b>Category</b>: containers</TD><TD Align=right VAlign=top><b>Component type</b>: type</TD></TR></Table><h3>Description</h3><tt>Set</tt> is a<A href="SortedAssociativeContainer.html">Sorted Associative Container</A> that stores objects of type <tt>Key</tt>.<tt>Set</tt> is a<A href="SimpleAssociativeContainer.html">Simple Associative Container</A>, meaning that its value type, as well as its key type, is <tt>Key</tt>.  It is also a<A href="UniqueAssociativeContainer.html">Unique Associative Container</A>,meaning that no two elements are the same.<P><tt>Set</tt> and <tt><A href="multiset.html">multiset</A></tt> areparticularly well suited to the set algorithms<tt><A href="includes.html">includes</A></tt>,<tt><A href="set_union.html">set_union</A></tt>,<tt><A href="set_intersection.html">set_intersection</A></tt>,<tt><A href="set_difference.html">set_difference</A></tt>, and<tt><A href="set_symmetric_difference.html">set_symmetric_difference</A></tt>.The reason for this is twofold.  First, the set algorithms requiretheir arguments to be sorted ranges, and, since<tt><A href="set.html">set</A></tt> and <tt><A href="multiset.html">multiset</A></tt> are <A href="SortedAssociativeContainer.html">Sorted Associative Containers</A>, their elements are always sorted in ascending order. Second, the output range of these algorithms is always sorted, andinserting a sorted range into a <tt>set</tt> or <tt>multiset</tt> is afast operation: the<A href="UniqueSortedAssociativeContainer.html">Unique Sorted Associative Container</A> and <A href="MultipleSortedAssociativeContainer.html">Multiple Sorted Associative Container</A>requirements guarantee that inserting arange takes only linear time if the range is already sorted.<P><tt>Set</tt> has the important property that inserting a new elementinto a <tt>set</tt> does not invalidate iterators that point to existingelements.  Erasing an element from a set also does not invalidateany iterators, except, of course, for iterators that actually point to the element that is being erased.<h3>Example</h3><pre>struct ltstr{  bool operator()(const char* s1, const char* s2) const  {    return strcmp(s1, s2) &lt; 0;  }};int main(){  const int N = 6;  const char* a[N] = {&quot;isomer&quot;, &quot;ephemeral&quot;, &quot;prosaic&quot;,                       &quot;nugatory&quot;, &quot;artichoke&quot;, &quot;serif&quot;};  const char* b[N] = {&quot;flat&quot;, &quot;this&quot;, &quot;artichoke&quot;,                      &quot;frigate&quot;, &quot;prosaic&quot;, &quot;isomer&quot;};  set&lt;const char*, ltstr&gt; A(a, a + N);  set&lt;const char*, ltstr&gt; B(b, b + N);  set&lt;const char*, ltstr&gt; C;  cout &lt;&lt; &quot;Set A: &quot;;  <A href="copy.html">copy</A>(A.begin(), A.end(), <A href="ostream_iterator.html">ostream_iterator</A>&lt;const char*&gt;(cout, &quot; &quot;));  cout &lt;&lt; endl;  cout &lt;&lt; &quot;Set B: &quot;;  <A href="copy.html">copy</A>(B.begin(), B.end(), <A href="ostream_iterator.html">ostream_iterator</A>&lt;const char*&gt;(cout, &quot; &quot;));     cout &lt;&lt; endl;  cout &lt;&lt; &quot;Union: &quot;;  <A href="set_union.html">set_union</A>(A.begin(), A.end(), B.begin(), B.end(),            <A href="ostream_iterator.html">ostream_iterator</A>&lt;const char*&gt;(cout, &quot; &quot;),            ltstr());     cout &lt;&lt; endl;  cout &lt;&lt; &quot;Intersection: &quot;;  <A href="set_intersection.html">set_intersection</A>(A.begin(), A.end(), B.begin(), B.end(),                   <A href="ostream_iterator.html">ostream_iterator</A>&lt;const char*&gt;(cout, &quot; &quot;),                   ltstr());      cout &lt;&lt; endl;  <A href="set_difference.html">set_difference</A>(A.begin(), A.end(), B.begin(), B.end(),                 <A href="insert_iterator.html">inserter</A>(C, C.begin()),                 ltstr());  cout &lt;&lt; &quot;Set C (difference of A and B): &quot;;  <A href="copy.html">copy</A>(C.begin(), C.end(), <A href="ostream_iterator.html">ostream_iterator</A>&lt;const char*&gt;(cout, &quot; &quot;));  cout &lt;&lt; endl;}</pre><h3>Definition</h3>Defined in the standard header <A href="set">set</A>, and in the nonstandardbackward-compatibility header <A href="set.h">set.h</A>.<h3>Template parameters</h3><Table border><TR><TH>Parameter</TH><TH>Description</TH><TH>Default</TH></TR><TR><TD VAlign=top><tt>Key</tt></TD><TD VAlign=top>The set's key type and value type.  This is also defined as <tt>set::key_type</tt>   and <tt>set::value_type</tt></TD><TD VAlign=top>&nbsp;</TD></TR><TR><TD VAlign=top><tt>Compare</tt></TD><TD VAlign=top>The key comparison function, a <A href="StrictWeakOrdering.html">Strict Weak Ordering</A> whose   argument type is <tt>key_type</tt>; it returns <tt>true</tt> if its first    argument is less than its second argument, and <tt>false</tt> otherwise.   This is also defined as <tt>set::key_compare</tt> and <tt>set::value_compare</tt>.</TD><TD VAlign=top><tt><A href="less.html">less</A>&lt;Key&gt;</tt></TD></TR><TR><TD VAlign=top><tt>Alloc</tt></TD><TD VAlign=top>The <tt>set</tt>'s allocator, used for all internal memory management.</TD><TD VAlign=top><tt><A href="Allocators.html">alloc</A></tt></TD></tr></table><h3>Model of</h3><A href="UniqueSortedAssociativeContainer.html">Unique Sorted Associative Container</A>, <A href="SimpleAssociativeContainer.html">Simple Associative Container</A><h3>Type requirements</h3><UL><LI><tt>Key</tt> is <A href="Assignable.html">Assignable</A>.<LI><tt>Compare</tt> is a <A href="StrictWeakOrdering.html">Strict Weak Ordering</A> whose argument type   is <tt>Key</tt>.<LI><tt>Alloc</tt> is an <A href="Allocators.html">Allocator</A>.</UL><h3>Public base classes</h3>None.<h3>Members</h3><Table border><TR><TH>Member</TH><TH>Where defined</TH><TH>Description</TH></TR><TR><TD VAlign=top><tt>value_type</tt></TD><TD VAlign=top> <A href="Container.html">Container</A></TD><TD VAlign=top>The type of object, <tt>T</tt>, stored in the set.</TD></TR><TR><TD VAlign=top><tt>key_type</tt></TD><TD VAlign=top> <A href="AssociativeContainer.html">Associative Container</A></TD><TD VAlign=top>The key type associated with <tt>value_type</tt>.</TD></TR><TR><TD VAlign=top><tt>key_compare</tt></TD><TD VAlign=top> <A href="SortedAssociativeContainer.html">Sorted Associative Container</A></TD><TD VAlign=top> <A href="functors.html">Function object</A> that compares two keys for ordering.</TD></TR><TR><TD VAlign=top><tt>value_compare</tt></TD><TD VAlign=top> <A href="SortedAssociativeContainer.html">Sorted Associative Container</A></TD><TD VAlign=top> <A href="functors.html">Function object</A> that compares two values for ordering.</TD></TR><TR><TD VAlign=top><tt>pointer</tt></TD><TD VAlign=top> <A href="Container.html">Container</A></TD><TD VAlign=top>Pointer to <tt>T</tt>.</TD></TR><TR><TD VAlign=top><tt>reference</tt></TD><TD VAlign=top> <A href="Container.html">Container</A></TD><TD VAlign=top>Reference to <tt>T</tt></TD></TR><TR><TD VAlign=top><tt>const_reference</tt></TD><TD VAlign=top> <A href="Container.html">Container</A></TD><TD VAlign=top>Const reference to <tt>T</tt></TD></TR><TR><TD VAlign=top><tt>size_type</tt></TD><TD VAlign=top> <A href="Container.html">Container</A></TD><TD VAlign=top>An unsigned integral type.</TD></TR><TR><TD VAlign=top><tt>difference_type</tt></TD><TD VAlign=top> <A href="Container.html">Container</A></TD><TD VAlign=top>A signed integral type.</TD></TR><TR><TD VAlign=top><tt>iterator</tt></TD><TD VAlign=top> <A href="Container.html">Container</A></TD><TD VAlign=top>Iterator used to iterate through a <tt>set</tt>.</TD></TR><TR><TD VAlign=top><tt>const_iterator</tt></TD><TD VAlign=top> <A href="Container.html">Container</A></TD><TD VAlign=top>Const iterator used to iterate through a <tt>set</tt>.  (<tt>Iterator</tt> and   <tt>const_iterator</tt> are the same type.)</TD></TR><TR><TD VAlign=top><tt>reverse_iterator</tt></TD><TD VAlign=top> <A href="ReversibleContainer.html">Reversible Container</A></TD><TD VAlign=top>Iterator used to iterate backwards through a <tt>set</tt>.</TD></TR><TR><TD VAlign=top><tt>const_reverse_iterator</tt></TD><TD VAlign=top> <A href="ReversibleContainer.html">Reversible Container</A></TD><TD VAlign=top>Const iterator used to iterate backwards through a <tt>set</tt>.  (<tt>Reverse_iterator</tt> and <tt>const_reverse_iterator</tt> are the same type.)</TD></TR><TR><TD VAlign=top><tt>iterator begin() const</tt></TD><TD VAlign=top> <A href="Container.html">Container</A></TD><TD VAlign=top>Returns an <tt>iterator</tt> pointing to the beginning of the <tt>set</tt>.</TD></TR><TR><TD VAlign=top><tt>iterator end() const</tt></TD><TD VAlign=top> <A href="Container.html">Container</A></TD><TD VAlign=top>Returns an <tt>iterator</tt> pointing to the end of the <tt>set</tt>.</TD></TR><TR><TD VAlign=top><tt>reverse_iterator rbegin() const</tt></TD><TD VAlign=top> <A href="ReversibleContainer.html">Reversible Container</A></TD><TD VAlign=top>Returns a <tt>reverse_iterator</tt> pointing to the beginning of the   reversed set.</TD></TR><TR><TD VAlign=top>

⌨️ 快捷键说明

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