?? container.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=NupaBtFCY34AAHZitM0">
<img src="http://ad.doubleclick.net/ad/www.codeguru.com/cpp;ord=NupaBtFCY34AAHZitM0"></a>
</p>
</noscript>
<BR Clear>
<H1>Container</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 = "concept.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>: concept</TD>
</TR>
</Table>
<h3>Description</h3>
A Container is an object that stores other objects (its <i>elements</i>),
and that has methods for accessing its elements. In particular,
every type that is a model of Container has an associated <A href="Iterators.html">iterator</A>
type that can be used to iterate through the Container's elements.
<P>
There is no guarantee that the elements of a Container are stored
in any definite order; the order might, in fact, be different upon
each iteration through the Container. Nor is there a guarantee that
more than one iterator into a Container may be active at any one time.
(Specific types of Containers, such as <A href="ForwardContainer.html">Forward Container</A>, do
provide such guarantees.)
<P>
A Container "owns" its elements: the lifetime of an element stored in
a container cannot exceed that of the Container itself. <A href="#1">[1]</A>
<h3>Refinement of</h3>
<A href="Assignable.html">Assignable</A>
<h3>Associated types</h3>
<Table border>
<TR>
<TD VAlign=top>
Value type
</TD>
<TD VAlign=top>
<tt>X::value_type</tt>
</TD>
<TD VAlign=top>
The type of the object stored in a container. The value type
must be <A href="Assignable.html">Assignable</A>, but need not be <A href="DefaultConstructible.html" tppabs="http://www.sgi.com/Technology/STL/DefaultConstructible.shtml">DefaultConstructible</A>. <A href="#2">[2]</A>
</TD>
</TR>
<TR>
<TD VAlign=top>
Iterator type
</TD>
<TD VAlign=top>
<tt>X::iterator</tt>
</TD>
<TD VAlign=top>
The type of iterator used to iterate through a container's
elements. The iterator's value type is expected to be the
container's value type. A conversion
from the iterator type to the const iterator type must exist.
The iterator type must be an <A href="InputIterator.html">input iterator</A>. <A href="#3">[3]</A>
</TD>
</TR>
<TR>
<TD VAlign=top>
Const iterator type
</TD>
<TD VAlign=top>
<tt>X::const_iterator</tt>
</TD>
<TD VAlign=top>
A type of iterator that may be used to examine, but not to modify,
a container's elements. <A href="#3">[3]</A> <A href="#4">[4]</A>
</TD>
</TR>
<TR>
<TD VAlign=top>
Reference type
</TD>
<TD VAlign=top>
<tt>X::reference</tt>
</TD>
<TD VAlign=top>
A type that behaves as a reference to the container's value type. <A href="#5">[5]</A>
</TD>
</TR>
<TR>
<TD VAlign=top>
Const reference type
</TD>
<TD VAlign=top>
<tt>X::const_reference</tt>
</TD>
<TD VAlign=top>
A type that behaves as a const reference to the container's value
type. <A href="#5">[5]</A>
</TD>
</TR>
<TR>
<TD VAlign=top>
Pointer type
</TD>
<TD VAlign=top>
<tt>X::pointer</tt>
</TD>
<TD VAlign=top>
A type that behaves as a pointer to the container's value type. <A href="#6">[6]</A>
</TD>
</TR>
<TR>
<TD VAlign=top>
Distance type
</TD>
<TD VAlign=top>
<tt>X::difference_type</tt>
</TD>
<TD VAlign=top>
A signed integral type used to represent the distance between two
of the container's iterators. This type must be the same as
the iterator's distance type. <A href="#2">[2]</A>
</TD>
</TR>
<TR>
<TD VAlign=top>
Size type
</TD>
<TD VAlign=top>
<tt>X::size_type</tt>
</TD>
<TD VAlign=top>
An unsigned integral type that can represent any nonnegative value
of the container's distance type. <A href="#2">[2]</A>
</TD>
</tr>
</table>
<h3>Notation</h3>
<Table>
<TR>
<TD VAlign=top>
<tt>X</tt>
</TD>
<TD VAlign=top>
A type that is a model of Container
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>a</tt>, <tt>b</tt>
</TD>
<TD VAlign=top>
Object of type <tt>X</tt>
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>T</tt>
</TD>
<TD VAlign=top>
The value type of <tt>X</tt>
</TD>
</tr>
</table>
<h3>Definitions</h3>
The <i>size</i> of a container is the number of elements it contains.
The size is a nonnegative number.
<P>
The <i>area</i> of a container is the total number of bytes that it
occupies. More specifically, it is the sum of the elements' areas
plus whatever overhead is associated with the container itself. If a
container's value type <tt>T</tt> is a simple type (as opposed to a container
type), then the container's area is bounded above by a constant times
the container's size times <tt>sizeof(T)</tt>. That is, if <tt>a</tt> is a
container with a simple value type, then <tt>a</tt>'s area is <tt>O(a.size())</tt>.
<P>
A <i>variable sized</i> container is one that provides methods for
inserting and/or removing elements; its size may vary during a
container's lifetime. A <i>fixed size</i> container is one where
the size is constant throughout the container's lifetime. In some
fixed-size container types, the size is determined at compile time.
<h3>Valid expressions</h3>
In addition to the expressions defined in
<A href="Assignable.html">Assignable</A>, <A href="EqualityComparable.html" tppabs="http://www.sgi.com/Technology/STL/EqualityComparable.shtml">EqualityComparable</A>, and <A href="LessThanComparable.html" tppabs="http://www.sgi.com/Technology/STL/LessThanComparable.shtml">LessThanComparable</A>, the
following expressions must be valid.
<Table border>
<TR>
<TH>
Name
</TH>
<TH>
Expression
</TH>
<TH>
Type requirements
</TH>
<TH>
Return type
</TH>
</TR>
<TR>
<TD VAlign=top>
Beginning of range
</TD>
<TD VAlign=top>
<tt>a.begin()</tt>
</TD>
<TD VAlign=top>
</TD>
<TD VAlign=top>
<tt>iterator</tt> if <tt>a</tt> is mutable, <tt>const_iterator</tt> otherwise <A href="#4">[4]</A> <A href="#7">[7]</A>
</TD>
</TR>
<TR>
<TD VAlign=top>
End of range
</TD>
<TD VAlign=top>
<tt>a.end()</tt>
</TD>
<TD VAlign=top>
</TD>
<TD VAlign=top>
<tt>iterator</tt> if <tt>a</tt> is mutable, <tt>const_iterator</tt> otherwise <A href="#4">[4]</A>
</TD>
</TR>
<TR>
<TD VAlign=top>
Size
</TD>
<TD VAlign=top>
<tt>a.size()</tt>
</TD>
<TD VAlign=top>
</TD>
<TD VAlign=top>
<tt>size_type</tt>
</TD>
</TR>
<TR>
<TD VAlign=top>
Maximum size
</TD>
<TD VAlign=top>
<tt>a.max_size()</tt>
</TD>
<TD VAlign=top>
</TD>
<TD VAlign=top>
<tt>size_type</tt>
</TD>
</TR>
<TR>
<TD VAlign=top>
Empty container
</TD>
<TD VAlign=top>
<tt>a.empty()</tt>
</TD>
<TD VAlign=top>
</TD>
<TD VAlign=top>
Convertible to <tt>bool</tt>
</TD>
</TR>
<TR>
<TD VAlign=top>
Swap
</TD>
<TD VAlign=top>
<tt>a.swap(b)</tt>
</TD>
<TD VAlign=top>
</TD>
<TD VAlign=top>
<tt>void</tt>
</TD>
</tr>
</table>
<h3>Expression semantics</h3>
Semantics of an expression is defined only where it differs from, or
is not defined in,
<A href="Assignable.html">Assignable</A>, <A href="EqualityComparable.html" tppabs="http://www.sgi.com/Technology/STL/EqualityComparable.shtml">Equality Comparable</A>,
or <A href="LessThanComparable.html">LessThan Comparable</A>
<Table border>
<TR>
<TH>
Name
</TH>
<TH>
Expression
</TH>
<TH>
Precondition
</TH>
<TH>
Semantics
</TH>
<TH>
Postcondition
</TH>
</TR>
<TR>
<TD VAlign=top>
Copy constructor
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -