?? container.html
字號:
</TD>
<TD VAlign=top>
<tt>X(a)</tt>
</TD>
<TD VAlign=top>
</TD>
<TD VAlign=top>
</TD>
<TD VAlign=top>
<tt>X().size() == a.size()</tt>. <tt>X()</tt> contains a copy of each of <tt>a</tt>'s elements.
</TD>
</TR>
<TR>
<TD VAlign=top>
Copy constructor
</TD>
<TD VAlign=top>
<tt>X b(a);</tt>
</TD>
<TD VAlign=top>
</TD>
<TD VAlign=top>
</TD>
<TD VAlign=top>
<tt>b.size() == a.size()</tt>. <tt>b</tt> contains a copy of each of <tt>a</tt>'s elements.
</TD>
</TR>
<TR>
<TD VAlign=top>
Assignment operator
</TD>
<TD VAlign=top>
<tt>b = a</tt>
</TD>
<TD VAlign=top>
</TD>
<TD VAlign=top>
</TD>
<TD VAlign=top>
<tt>b.size() == a.size()</tt>. <tt>b</tt> contains a copy of each of <tt>a</tt>'s elements.
</TD>
</TR>
<TR>
<TD VAlign=top>
Destructor
</TD>
<TD VAlign=top>
<tt>a.~X()</tt>
</TD>
<TD VAlign=top>
</TD>
<TD VAlign=top>
Each of <tt>a</tt>'s elements is destroyed, and memory allocated for them
(if any) is deallocated.
</TD>
<TD VAlign=top>
</TD>
</TR>
<TR>
<TD VAlign=top>
Beginning of range
</TD>
<TD VAlign=top>
<tt>a.begin()</tt>
</TD>
<TD VAlign=top>
</TD>
<TD VAlign=top>
Returns an iterator pointing to the first element in the container. <A href="#7">[7]</A>
</TD>
<TD VAlign=top>
<tt>a.begin()</tt> is either dereferenceable or past-the-end. It is
past-the-end if and only if <tt>a.size() == 0</tt>.
</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>
Returns an iterator pointing one past the last element in the
container.
</TD>
<TD VAlign=top>
<tt>a.end()</tt> is past-the-end.
</TD>
</TR>
<TR>
<TD VAlign=top>
Size
</TD>
<TD VAlign=top>
<tt>a.size()</tt>
</TD>
<TD VAlign=top>
</TD>
<TD VAlign=top>
Returns the size of the container, that is, its number of elements. <A href="#8">[8]</A>
</TD>
<TD VAlign=top>
<tt>a.size() >= 0 && a.size() <= max_size()</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>
Returns the largest size that this container can ever have. <A href="#8">[8]</A>
</TD>
<TD VAlign=top>
<tt>a.max_size() >= 0 && a.max_size() >= a.size()</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>
Equivalent to <tt>a.size() == 0</tt>. (But possibly faster.)
</TD>
<TD VAlign=top>
</TD>
</TR>
<TR>
<TD VAlign=top>
Swap
</TD>
<TD VAlign=top>
<tt>a.swap(b)</tt>
</TD>
<TD VAlign=top>
</TD>
<TD VAlign=top>
Equivalent to <tt>swap(a,b)</tt> <A href="#9">[9]</A>
</TD>
<TD VAlign=top>
</TD>
</tr>
</table>
<h3>Complexity guarantees</h3>
The copy constructor, the assignment operator, and the destructor
are linear in the container's size.
<P>
<tt>begin()</tt> and <tt>end()</tt> are amortized constant time.
<P>
<tt>size()</tt> is linear in the
container's size. <A href="#10">[10]</A> <tt>max_size()</tt> and
<tt>empty()</tt> are amortized constant time. If you are
testing whether a container is empty, you should always write
<tt>c.empty()</tt> instead of <tt>c.size() == 0</tt>. The two expressions are
equivalent, but the former may be much faster.
<P>
<tt>swap()</tt> is amortized constant time. <A href="#9">[9]</A>
<h3>Invariants</h3>
<Table border>
<TR>
<TD VAlign=top>
Valid range
</TD>
<TD VAlign=top>
For any container <tt>a</tt>, <tt>[a.begin(), a.end())</tt> is a valid
range. <A href="#11">[11]</A>
</TD>
</TR>
<TR>
<TD VAlign=top>
Range size
</TD>
<TD VAlign=top>
<tt>a.size()</tt> is equal to the distance from <tt>a.begin()</tt> to <tt>a.end()</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
Completeness
</TD>
<TD VAlign=top>
An algorithm that iterates through the range <tt>[a.begin(), a.end())</tt>
will pass through every element of <tt>a</tt>. <A href="#11">[11]</A>
</TD>
</tr>
</table>
<h3>Models</h3>
<UL>
<LI>
<A href="Vector.html">vector</A>
</UL>
<h3>Notes</h3>
<P><A name="1">[1]</A>
The fact that the lifetime of elements cannot exceed that of of
their container may seem like a severe restriction. In fact, though,
it is not. Note that pointers and iterators are objects; like any
other objects, they may be stored in a container. The container, in
that case, "owns" the pointers themselves, but not the objects that
they point to.
<P><A name="2">[2]</A>
This expression must be a <tt>typedef</tt>, that is, a synonym for
a type that already has some other name.
<P><A name="3">[3]</A>
This may either be a <tt>typedef</tt> for some other type, or else
a unique type that is defined as a nested class within the class
<tt>X</tt>.
<P><A name="4">[4]</A>
A container's iterator type and const iterator type may be the
same: there is no guarantee that every container must have an
associated mutable iterator type. For example, <tt><A href="set.html">set</A></tt> and
<tt><A href="hash_set.html">hash_set</A></tt> define <tt>iterator</tt> and <tt>const_iterator</tt> to be
the same type.
<P><A name="5">[5]</A>
It is required that the reference type has the same semantics as
an ordinary C++ reference, but it need not actually be an ordinary C++
reference. Some implementations, for example, might provide
additional reference types to support non-standard memory models.
Note, however, that "smart references" (user-defined reference types
that provide additional functionality) are not a viable option. It is
impossible for a user-defined type to have the same semantics as C++
references, because the C++ language does not support redefining the
member access operator (<tt>operator.</tt>).
<P><A name="6">[6]</A>
As in the case of references <A href="#5">[5]</A>, the pointer type must have the
same semantics as C++ pointers but need not actually be a C++ pointer.
"Smart pointers," however, unlike "smart references", are possible.
This is because it is possible for user-defined types to define the
dereference operator and the pointer member access operator,
<tt>operator*</tt> and <tt>operator-></tt>.
<P><A name="7">[7]</A>
The iterator type need only be an <i>input iterator</i>, which
provides a very weak set of guarantees; in particular, all algorithms
on input iterators must be "single pass". It follows that only a single
iterator into a container may be active at any one time. This restriction
is removed in <A href="ForwardContainer.html">Forward Container</A>.
<P><A name="8">[8]</A>
In the case of a fixed-size container, <tt>size() == max_size()</tt>.
<P><A name="9">[9]</A>
For any <A href="Assignable.html">Assignable</A> type, <A href="swap.html" tppabs="http://www.sgi.com/Technology/STL/swap.shtml">swap</A> can be defined in terms of
assignment. This requires three assignments, each of which, for
a container type, is linear in the container's size. In a sense,
then, <tt>a.swap(b)</tt> is redundant. It exists solely for the sake of
efficiency: for many containers, such as <A href="Vector.html">vector</A> and <A href="List.html" tppabs="http://www.sgi.com/Technology/STL/List.shtml">list</A>,
it is possible to implement <tt>swap</tt> such that its run-time complexity
is constant rather than linear. If this is possible for some container
type <tt>X</tt>, then the template specialization <tt><A href="swap.html">swap</A>(X&, X&)</tt> can
simply be written in terms of <tt>X::swap(X&)</tt>. The implication of this
is that <tt>X::swap(X&)</tt> should <b>only</b> be defined if there exists such
a constant-time implementation. Not every container class <tt>X</tt> need
have such a member function, but if the member function exists at all then
it is guaranteed to be amortized constant time.
<P><A name="10">[10]</A>
For many containers, such as <tt><A href="Vector.html">vector</A></tt> and <tt><A href="Deque.html" tppabs="http://www.sgi.com/Technology/STL/Deque.shtml">deque</A></tt>, <tt>size</tt> is
<i>O(1</i>). This satisfies the requirement that it be <i>O(N</i>).
<P><A name="11">[11]</A>
Although <tt>[a.begin(), a.end())</tt> must be a valid range, and must
include every element in the container, the order in which the elements
appear in that range is unspecified. If you iterate through a container
twice, it is not guaranteed that the order will be the same both
times. This restriction is removed in <A href="ForwardContainer.html">Forward Container</A>.
<h3>See also</h3>
The <A href="Iterators.html">Iterator overview</A>, <A href="InputIterator.html" tppabs="http://www.sgi.com/Technology/STL/InputIterator.shtml">Input Iterator</A>, <A href="Sequence.html" tppabs="http://www.sgi.com/Technology/STL/Sequence.shtml">Sequence</A>
<HR SIZE="6"> <FONT SIZE="-2"> Copyright © 1996 Silicon Graphics, Inc.
<HR>
<TABLE BORDER=0 WIDTH="100%" >
<TR>
<TD WIDTH="33%"><FONT SIZE=-1><A HREF="index.html" >
STL</A></FONT></TD>
<TD WIDTH="33%">
<CENTER><FONT SIZE=-2>© Copyright 1997-1998 CodeGuru</FONT> </CENTER>
</TD>
<TD WIDTH="34%">
<DIV ALIGN=right><FONT SIZE=-1>Contact : <A HREF="mailto:webmaster@codeguru.com">webmaster@codeguru.com</A> </FONT></DIV>
</TD>
</TR>
</TABLE>
<SCRIPT LANGUAGE="JavaScript" ><!--
var adurl = "/cgi-bin/doubleclick.cgi?";
if( self.adcategory )
adurl += adcategory;
else
adurl += "mfc";
if( self.parent.norefreshad )
parent.norefreshad = false;
else if( validframes )
parent.frames['ad'].location = adurl;
if( !validframes && nfrm == -1)
{
var dclkPage = "www.codeguru.com/";
if( self.adcategory )
dclkPage += adcategory;
else
dclkPage += "mfc";
// var random = Math.random();
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>');
}
// -->
</SCRIPT>
<!-- SCRIPT LANGUAGE="JavaScript" SRC="/global/fscript.js">
//
</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>
</BODY>
</HTML>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -