📄 multiset.html
字号:
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Author" CONTENT="Zafir Anjum">
<TITLE>MFC Programmer's SourceBook : STL Programmer's Guide</TITLE>
<META name="description"
content="A freely available implementation
of the C++ Standard Template Library, including
hypertext documentation.">
<META name="keywords"
content="generic programming, STL, standard template library">
</HEAD>
<SCRIPT LANGUAGE="JavaScript"><!--
var adcategory = "cpp";
// -->
</SCRIPT>
<body background="../../fancyhome/back.gif" bgcolor="#FFFFFF" >
<SCRIPT LANGUAGE="JavaScript"><!--
var nfrm = location.href.indexOf("_nfrm_");
var validframes = (top.frames.length > 0 && top.frames['ad'] && top.frames['logo'] );
var random = Math.random();
if( !validframes && nfrm == -1 )
{
var dclkPage = "www.codeguru.com/";
if( self.adcategory )
dclkPage += adcategory;
else
dclkPage += "mfc";
document.write('<nolayer><center>');
document.write('<iframe src="http://ad.doubleclick.net/adi/' + dclkPage + ';ord='
+ random + '" width=470 height=62 marginwidth=0 marginheight=0 hspace=0 vspace=0 '
+ 'frameborder=0 scrolling=no bordercolor="#000000">');
document.write('<a href="http://ad.doubleclick.net/jump/' + dclkPage + ';ord='
+ random + '">');
document.write('<img src="http://ad.doubleclick.net/ad/' + dclkPage + ';ord='
+ random + '" height=60 width=468>' + '</a>');
document.write('</iframe>');
document.write('</center></nolayer>');
document.write('<layer src="http://ad.doubleclick.net/adl/' + dclkPage +
';ord=' + random + '"></layer>');
document.write('<ilayer visibility=hide width=468 height=83></ilayer>');
}
// top.location = "/show.cgi?" + adcategory + "=" + location.pathname;
// -->
</SCRIPT>
<noscript>
<p align="center">
<a href="http://ad.doubleclick.net/jump/www.codeguru.com/cpp;ord=NupaR9FCY34AAHKMEVk">
<img src="http://ad.doubleclick.net/ad/www.codeguru.com/cpp;ord=NupaR9FCY34AAHKMEVk"></a>
</p>
</noscript>
<BR Clear>
<H1>multiset<Key, Compare, Alloc></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 = "39" ></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>Multiset</tt> is a
<A href="SortedAssociativeContainer.html">Sorted Associative Container</A>
that stores objects of type <tt>Key</tt>.
<tt>Multiset</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="MultipleAssociativeContainer.html">Multiple Associative Container</A>,
meaning that two or more elements may be identical.
<P>
<tt><A href="set.html">Set</A></tt> and <tt>multiset</tt>
are particularly 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 require
their arguments to be sorted ranges, and, since
<tt><A href="set.html">set</A></tt> and <tt><A href="multiset.html" tppabs="http://www.sgi.com/Technology/STL/multiset.shtml">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, and
inserting a sorted range into a <tt>set</tt> or <tt>multiset</tt> is a
fast 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 a
range takes only linear time if the range is already sorted.
<P>
<tt>Multiset</tt> has the important property that inserting a new element
into a <tt>multiset</tt> does not invalidate iterators that point to existing
elements. Erasing an element from a multiset also does not invalidate
any iterators, except, of course, for iterators that actually point
to the element that is being erased.
<h3>Example</h3>
<pre>
int main()
{
const int N = 10;
int a[N] = {4, 1, 1, 1, 1, 1, 0, 5, 1, 0};
int b[N] = {4, 4, 2, 4, 2, 4, 0, 1, 5, 5};
multiset<int> A(a, a + N);
multiset<int> B(b, b + N);
multiset<int> C;
cout << "Set A: ";
<A href="copy.html">copy</A>(A.begin(), A.end(), <A href="ostream_iterator.html" tppabs="http://www.sgi.com/Technology/STL/ostream_iterator.shtml">ostream_iterator</A><int>(cout, " "));
cout << endl;
cout << "Set B: ";
<A href="copy.html">copy</A>(B.begin(), B.end(), <A href="ostream_iterator.html" tppabs="http://www.sgi.com/Technology/STL/ostream_iterator.shtml">ostream_iterator</A><int>(cout, " "));
cout << endl;
cout << "Union: ";
<A href="set_union.html">set_union</A>(A.begin(), A.end(), B.begin(), B.end(),
<A href="ostream_iterator.html">ostream_iterator</A><int>(cout, " "));
cout << endl;
cout << "Intersection: ";
<A href="set_intersection.html">set_intersection</A>(A.begin(), A.end(), B.begin(), B.end(),
<A href="ostream_iterator.html">ostream_iterator</A><int>(cout, " "));
cout << 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()));
cout << "Set C (difference of A and B): ";
<A href="copy.html">copy</A>(C.begin(), C.end(), <A href="ostream_iterator.html" tppabs="http://www.sgi.com/Technology/STL/ostream_iterator.shtml">ostream_iterator</A><int>(cout, " "));
cout << endl;
}
</pre>
<h3>Definition</h3>
<tt>Multiset</tt> is declared in <A href="multiset.h">multiset.h</A>.
The implementation is in <A href="multiset.h">multiset.h</A>
and <A href="tree.h">tree.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>multiset::key_type</tt>
and <tt>multiset::value_type</tt>
</TD>
<TD VAlign=top>
</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>multiset::key_compare</tt> and <tt>multiset::value_compare</tt>.
</TD>
<TD VAlign=top>
<tt><A href="less.html">less</A><Key></tt>
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>Alloc</tt>
</TD>
<TD VAlign=top>
The <tt>multiset</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="MultipleSortedAssociativeContainer.html">Multiple 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 multiset.
</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>multiset</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>multiset</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>multiset</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>multiset</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>multiset</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>multiset</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 multiset.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>reverse_iterator rend() 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 end of the
reversed multiset.
</TD>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -