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

📄 mul_0958.htm

📁 ARM编辑、编译软件
💻 HTM
📖 第 1 页 / 共 2 页
字号:
</UL>
<A NAME="Member Functions"><H3>Member Functions</H3></A>
<PRE>void
<B>clear</B> ();</PRE>
<UL><P>Erases all elements from the self.</P>
</UL>
<PRE>size_type 
<B>count</B> (const key_type&#38; x) const;</PRE>
<UL><P>Returns the number of elements in the multiset with the key value <SAMP>x</SAMP>. </P>
</UL>
<PRE>bool 
<B>empty</B> () const;</PRE>
<UL><P>Returns <SAMP>true</SAMP> if the multiset is empty, <SAMP>false</SAMP> otherwise.</P>
</UL>
<PRE>pair&#60;iterator,iterator> 
<B>equal_range</B> (const key_type&#38; x)const;</PRE>
<UL><P>Returns the pair <SAMP>(lower_bound(x), upper_bound(x))</SAMP>.</P>
</UL>
<PRE>size_type 
<B>erase</B> (const key_type&#38; x);</PRE>
<UL><P>Deletes all elements with the key value <SAMP>x</SAMP> from the multiset, if any exist.  Returns the number of deleted elements.</P>
</UL>
<PRE>iterator
<B>erase</B> (iterator position);</PRE>
<UL><P>Deletes the multiset element pointed to by the iterator <SAMP>position</SAMP>. Returns an <SAMP>iterator</SAMP> pointing to the element following the deleted element, or <SAMP>end()</SAMP> if the deleted item was the last one in this list.</P>
</UL>
<PRE>iterator
<B>erase</B> (iterator first, iterator last);</PRE>
<UL><P>Providing the iterators <SAMP>first</SAMP> and <SAMP>last</SAMP> point to the same multiset and last is reachable from first, all elements in the range (<SAMP>first, last</SAMP>) will be deleted from the multiset. Returns an <SAMP>iterator</SAMP> pointing to the element following the last deleted element, or <SAMP>end()</SAMP> if there were no elements after the deleted range.</P>
</UL>
<PRE>iterator 
<B>find</B> (const key_type&#38; x) const;</PRE>
<UL><P>Searches the multiset for a key value <SAMP>x</SAMP> and returns an <SAMP>iterator</SAMP> to that key if it is found.  If such a value is not found the iterator <SAMP>end()</SAMP> is returned. </P>
</UL>
<PRE>iterator 
<B>insert</B> (const value_type&#38; x);
iterator 
<B>insert</B> (iterator position, const value_type&#38; x);</PRE>
<UL><P><SAMP>x</SAMP> is inserted into the multiset.  A position may be supplied as a hint regarding where to do the insertion.  If the insertion may be done right after position, then it takes amortized constant time.  Otherwise, it will take <SAMP>O(log N) </SAMP>time. </P>
</UL>
<PRE>template &#60;class InputIterator>
void 
<B>insert</B> (InputIterator first, InputIterator last);</PRE>
<UL><P>Copies of each element in the range <SAMP>[first, last)</SAMP> will be  inserted  into the multiset.  This <SAMP>insert</SAMP> takes approximately <SAMP>O(N*log(size()+N))</SAMP> time. </P>
</UL>
<PRE>key_compare 
<B>key_comp</B> () const;</PRE>
<UL><P>Returns a function object capable of comparing key values using the comparison operation, <SAMP>Compare</SAMP>, of the current multiset. </P>
</UL>
<PRE>iterator 
<B>lower_bound</B> (const key_type&#38; x) const;</PRE>
<UL><P>Returns an iterator to the  first element whose key is greater than or equal to <SAMP>x</SAMP>.  If no such element exists, <SAMP>end()</SAMP> is returned. </P>
</UL>
<PRE>size_type 
<B>max_size</B> () const;</PRE>
<UL><P>Returns the maximum possible size of the multiset <SAMP>size_type.</SAMP></P>
</UL>
<PRE>size_type
<B>size</B> () const;</PRE>
<UL><P>Returns the number of elements in the multiset.</P>
</UL>
<PRE>void 
<B>swap</B> (multiset&#60;Key, Compare, Allocator>&#38; x);</PRE>
<UL><P>Swaps the contents of the multiset <SAMP>x</SAMP> with the current multiset, <SAMP>*this</SAMP>. </P>
</UL>
<PRE>iterator 
<B>upper_bound </B>(const key_type&#38; x) const;</PRE>
<UL><P>Returns an <SAMP>iterator</SAMP> to the first  element whose key is smaller than or equal to <SAMP>x.</SAMP>  If no such element exists then <SAMP>end() </SAMP>is returned. </P>
</UL>
<PRE>value_compare 
<B>value_comp</B> () const;</PRE>
<UL><P>Returns a function object capable of comparing key values using the comparison operation, <SAMP>Compare</SAMP>, of the current  multiset.</P>
</UL>
<A NAME="Non-member Operators"><H3>Non-member Operators</H3></A>
<PRE>template &#60;class Key, class Compare, class Allocator>
<B>operator== </B>(const multiset&#60;Key, Compare, Allocator>&#38; x,
            const multiset&#60;Key, Compare, Allocator>&#38; y);</PRE>
<UL><P>Returns <SAMP>true</SAMP> if all  elements in <SAMP>x</SAMP> are element-wise equal to all elements in <SAMP>y</SAMP>, using <SAMP>(T::operator==)</SAMP>. Otherwise it returns <SAMP>false</SAMP>. </P>
</UL>
<PRE>template &#60;class Key, class Compare, class Allocator>
<B>operator&#60;</B> (const multiset&#60;Key, Compare, Allocator>&#38; x,
           const multiset&#60;Key, Compare, Allocator>&#38; y);</PRE>
<UL><P>Returns <SAMP>true</SAMP> if <SAMP>x</SAMP> is lexicographically less than y. Otherwise, it returns <SAMP>false</SAMP>. </P>
</UL>
<PRE>template &#60;class Key, class Compare, class Allocator>
void <B>swap</B> (multiset&#60;Key,Compare,Allocator>&#38; a,
           multiset&#60;Key,Compare,Allocator>&#38;b);</PRE>
<UL><P>Efficiently swaps the contents of <SAMP>a</SAMP> and <SAMP>b</SAMP>.</P>
</UL>
<A NAME="Example"><H3>Example</H3></A>
<PRE>//
// multiset.cpp
//
#include &#60;set>
#iclude &#60;iostream.h>
 typedef <B>multiset</B>&#60;int, less&#60;int>, allocator> set_type;
 ostream&#38; operator&#60;&#60;(ostream&#38; out, const set_type&#38; s)
 {
   copy(s.begin(),s.end(),
        ostream_iterator&#60;set_type::value_type>(cout," "));
   return out;
 }
 int main(void)
 {
   // create a multiset of ints
   set_type  si;
   int  i;
   for (int j = 0; j &#60; 2; j++)
   {
     for(i = 0; i &#60; 10; ++i) {
       // insert values with a hint
       si.insert(si.begin(), i);
     }
   }
   // print out the multiset
   cout &#60;&#60; si &#60;&#60; endl;
   // Make another int multiset and an empty multiset
   set_type si2, siResult;
   for (i = 0; i &#60; 10; i++)
      si2.insert(i+5);
   cout &#60;&#60; si2 &#60;&#60; endl;
   // Try a couple of set algorithms
   set_union(si.begin(),si.end(),si2.begin(),si2.end(),
          inserter(siResult,siResult.begin()));
   cout &#60;&#60; "Union:" &#60;&#60; endl &#60;&#60; siResult &#60;&#60; endl;
   siResult.erase(siResult.begin(),siResult.end());
   set_intersection(si.begin(),si.end(),
          si2.begin(),si2.end(),
          inserter(siResult,siResult.begin()));
   cout &#60;&#60; "Intersection:" &#60;&#60; endl &#60;&#60; siResult &#60;&#60; endl;
  
   return 0;
 }
Output: 
0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9
5 6 7 8 9 10 11 12 13 14
Union:
0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 11 12 13 14
Intersection:
5 6 7 8 9
</PRE>
<A NAME="Warnings"><H3>Warnings</H3></A>
<P>Member function templates are used in all containers  provided by the Standard Template Library.  An example of this feature is the constructor for<B><I> multiset&#60;Key, Compare, Allocator></B></I>, which takes two templated iterators: </P>
<PRE>template &#60;class InputIterator>
multiset (InputIterator, InputIterator,
          const Compare&#38; = Compare(),
          const Allocator&#38; = Allocator());
</PRE><P><B><I>multiset</B></I> also has an <SAMP>insert</SAMP> function of  this type.  These functions, when not restricted by compiler limitations, allow you to use any type of input iterator as arguments. For compilers that do not support this feature, we provide substitute functions that allow you to use an iterator obtained from the same type of container as the one you are constructing (or calling a member function on).  You can also  use a pointer to the type of element you have in the container. </P>
<P>For example, if your compiler does not support member  function templates, you can construct a <B><I>multiset</B></I> in the following two ways: </P>
<PRE>int intarray[10];
multiset&#60;int, less&#60;int>, allocator> first_multiset(intarray, 
                                                   intarray +10);
multiset&#60;int, less&#60;int> , allocator>
   second_multiset(first_multiset.begin(), first_multiset.end());
</PRE>
<P>but not this way:</P>
<PRE>multiset&#60;long, less&#60;long>, allocator>
   long_multiset(first_multiset.begin(),first_multiset.end());</PRE>
<P>since the <SAMP>long_multiset</SAMP> and<SAMP> first_multiset </SAMP>are not the  same type. </P>
<P>Also, many compilers do not support default template arguments.  If your compiler is one of these you need to always supply the <SAMP>Compare</SAMP> template argument and the <SAMP>Allocator</SAMP> template argument. For instance, you'll have to write:</P>
<PRE>multiset&#60;int, less&#60;int>, allocator></PRE>
<P>instead of:</P>
<PRE>multiset&#60;int></PRE>
<A NAME="See Also"><H3>See Also</H3></A>
<P><A HREF="all_7029.htm"><B><I>allocator</B></I></A>, <A HREF="Con_2487.htm"><B><I>Containers</B></I></A>, <A HREF="Ite_5295.htm"><B><I>Iterators</B></I></A>, <A HREF="set_1649.htm"><B><I>set</B></I></A></P>
<HR>
<A HREF="mul_8396.htm"><IMG SRC="images/prev.gif"></A> <A HREF="ref.htm#contents"><IMG SRC="images/toc.gif"></A> <A HREF="neg_4682.htm"><IMG SRC="images/next.gif"></A></BODY></HTML>

⌨️ 快捷键说明

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