📄 vector.html
字号:
<HTML><HEAD><TITLE><vector></TITLE></HEAD><BODY><H1><A NAME="<vector>"><CODE><vector></CODE></A></H1><HR><P>Include the <A HREF="index.html#STL">STL</A>standard header <B><CODE><vector></CODE></B> to define the<A HREF="lib_cont.html#Containers">container</A>template class <CODE>vector</CODE> and several supportingtemplates.</P><PRE>namespace std {template<class Ty, class Alloc> class <B><A HREF="#vector">vector</A></B>;template<class Alloc> class <B><A HREF="#vector<bool>">vector<bool></A></B>; // TEMPLATE FUNCTIONStemplate<class Ty, class Alloc> bool <B><A HREF="#operator==">operator==</A></B>( const vector<Ty, Alloc>& left, const vector<Ty, Alloc>& right);template<class Ty, class Alloc> bool <B><A HREF="#operator!=">operator!=</A></B>( const vector<Ty, Alloc>& left, const vector<Ty, Alloc>& right);template<class Ty, class Alloc> bool <B><A HREF="#operator<">operator<</A></B>( const vector<Ty, Alloc>& left, const vector<Ty, Alloc>& right);template<class Ty, class Alloc> bool <B><A HREF="#operator>">operator></A></B>( const vector<Ty, Alloc>& left, const vector<Ty, Alloc>& right);template<class Ty, class Alloc> bool <B><A HREF="#operator<=">operator<=</A></B>( const vector<Ty, Alloc>& left, const vector<Ty, Alloc>& right);template<class Ty, class Alloc> bool <B><A HREF="#operator>=">operator>=</A></B>( const vector<Ty, Alloc>& left, const vector<Ty, Alloc>& right);template<class Ty, class Alloc> void <B><A HREF="#swap">swap</A></B>( vector<Ty, Alloc>& left, vector<Ty, Alloc>& right); };</PRE><H2><A NAME="operator!="><CODE>operator!=</CODE></A></H2><PRE>template<class Ty, class Alloc> bool <B>operator!=</B>( const vector <Ty, Alloc>& left, const vector <Ty, Alloc>& right);</PRE><P>The template function returns <CODE>!(left == right)</CODE>.</P><H2><A NAME="operator=="><CODE>operator==</CODE></A></H2><PRE>template<class Ty, class Alloc> bool <B>operator==</B>( const vector <Ty, Alloc>& left, const vector <Ty, Alloc>& right);</PRE><P>The template function overloads <CODE>operator==</CODE> to comparetwo objects of template class<A HREF="#vector"><CODE>vector</CODE></A>. The function returns<CODE>left.<A HREF="#vector::size">size</A>() == right.size() &&<A HREF="algorith.html#equal">equal</A>(left.<A HREF="#vector::begin">begin</A>(), left.<A HREF="#vector::end">end</A>(), right.begin())</CODE>.</P><H2><A NAME="operator<"><CODE>operator<</CODE></A></H2><PRE>template<class Ty, class Alloc> bool <B>operator<</B>( const vector <Ty, Alloc>& left, const vector <Ty, Alloc>& right);</PRE><P>The template function overloads <CODE>operator<</CODE> to comparetwo objects of template class<A HREF="#vector"><CODE>vector</CODE></A>. The function returns<CODE><A HREF="algorith.html#lexicographical_compare">lexicographical_compare</A>(left.<A HREF="#vector::begin">begin</A>(), left.<A HREF="#vector::end">end</A>(), right.begin(), right.end())</CODE>.</P><H2><A NAME="operator<="><CODE>operator<=</CODE></A></H2><PRE>template<class Ty, class Alloc> bool <B>operator<=</B>( const vector <Ty, Alloc>& left, const vector <Ty, Alloc>& right);</PRE><P>The template function returns <CODE>!(right < left)</CODE>.</P><H2><A NAME="operator>"><CODE>operator></CODE></A></H2><PRE>template<class Ty, class Alloc> bool <B>operator></B>( const vector <Ty, Alloc>& left, const vector <Ty, Alloc>& right);</PRE><P>The template function returns <CODE>right < left</CODE>.</P><H2><A NAME="operator>="><CODE>operator>=</CODE></A></H2><PRE>template<class Ty, class Alloc> bool <B>operator>=</B>( const vector <Ty, Alloc>& left, const vector <Ty, Alloc>& right);</PRE><P>The template function returns <CODE>!(left < right)</CODE>.</P><H2><A NAME="swap"><CODE>swap</CODE></A></H2><PRE>template<class Ty, class Alloc> void <B>swap</B>( vector <Ty, Alloc>& left, vector <Ty, Alloc>& right);</PRE><P>The template function executes<CODE>left.<A HREF="#vector::swap">swap</A>(right)</CODE>.</P><H2><A NAME="vector"><CODE>vector</CODE></A></H2><HR><P><B><CODE><A HREF="#vector::allocator_type">allocator_type</A>· <A HREF="#vector::assign">assign</A>· <A HREF="#vector::at">at</A>· <A HREF="#vector::back">back</A>· <A HREF="#vector::begin">begin</A>· <A HREF="#vector::capacity">capacity</A>· <A HREF="#vector::clear">clear</A>· <A HREF="#vector::const_iterator">const_iterator</A>· <A HREF="#vector::const_pointer">const_pointer</A>· <A HREF="#vector::const_reference">const_reference</A>· <A HREF="#vector::const_reverse_iterator">const_reverse_iterator</A>· <A HREF="#vector::difference_type">difference_type</A>· <A HREF="#vector::empty">empty</A>· <A HREF="#vector::end">end</A>· <A HREF="#vector::erase">erase</A>· <A HREF="#vector::front">front</A>· <A HREF="#vector::get_allocator">get_allocator</A>· <A HREF="#vector::insert">insert</A>· <A HREF="#vector::iterator">iterator</A>· <A HREF="#vector::max_size">max_size</A>· <A HREF="#vector::operator[]">operator[]</A>· <A HREF="#vector::pointer">pointer</A>· <A HREF="#vector::pop_back">pop_back</A>· <A HREF="#vector::push_back">push_back</A>· <A HREF="#vector::rbegin">rbegin</A>· <A HREF="#vector::reference">reference</A>· <A HREF="#vector::rend">rend</A>· <A HREF="#vector::reserve">reserve</A>· <A HREF="#vector::resize">resize</A>· <A HREF="#vector::reverse_iterator">reverse_iterator</A>· <A HREF="#vector::size">size</A>· <A HREF="#vector::size_type">size_type</A>· <A HREF="#vector::swap">swap</A>· <A HREF="#vector::value_type">value_type</A>· <A HREF="#vector::vector">vector</A></CODE></B></P><HR><PRE>template<class Ty, class Alloc = allocator<Ty> > class <B>vector</B> {public: typedef Alloc <B><A HREF="#vector::allocator_type">allocator_type</A></B>; typedef typename Alloc::pointer <B><A HREF="#vector::pointer">pointer</A></B>; typedef typename Alloc::const_pointer <B><A HREF="#vector::const_pointer">const_pointer</A></B>; typedef typename Alloc::reference <B><A HREF="#vector::reference">reference</A></B>; typedef typename Alloc::const_reference <B><A HREF="#vector::const_reference">const_reference</A></B>; typedef typename Alloc::value_type <B><A HREF="#vector::value_type">value_type</A></B>; typedef T0 <B><A HREF="#vector::iterator">iterator</A></B>; typedef T1 <B><A HREF="#vector::const_iterator">const_iterator</A></B>; typedef T2 <B><A HREF="#vector::size_type">size_type</A></B>; typedef T3 <B><A HREF="#vector::difference_type">difference_type</A></B>; typedef reverse_iterator<const_iterator> <B><A HREF="#vector::const_reverse_iterator">const_reverse_iterator</A></B>; typedef reverse_iterator<iterator> <B><A HREF="#vector::reverse_iterator">reverse_iterator</A></B>; <B><A HREF="#vector::vector">vector</A></B>(); explicit <B><A HREF="#vector::vector">vector</A></B>(const Alloc& al); explicit <B><A HREF="#vector::vector">vector</A></B>(size_type count); <B><A HREF="#vector::vector">vector</A></B>(size_type count, const Ty& val); <B><A HREF="#vector::vector">vector</A></B>(size_type count, const Ty& val, const Alloc& al); <B><A HREF="#vector::vector">vector</A></B>(const vector& right); template<class InIt> <B><A HREF="#vector::vector">vector</A></B>(InIt first, InIt last); template<class InIt> <B><A HREF="#vector::vector">vector</A></B>(InIt first, InIt last, const Alloc& al); void <B><A HREF="#vector::reserve">reserve</A></B>(size_type count); size_type <B><A HREF="#vector::capacity">capacity</A></B>() const; iterator <B><A HREF="#vector::begin">begin</A></B>(); const_iterator <B><A HREF="#vector::begin">begin</A></B>() const; iterator <B><A HREF="#vector::end">end</A></B>(); const_iterator <B><A HREF="#vector::end">end</A></B>() const; reverse_iterator <B><A HREF="#vector::rbegin">rbegin</A></B>(); const_reverse_iterator <B><A HREF="#vector::rbegin">rbegin</A></B>() const; reverse_iterator <B><A HREF="#vector::rend">rend</A></B>(); const_reverse_iterator <B><A HREF="#vector::rend">rend</A></B>() const; void <B><A HREF="#vector::resize">resize</A></B>(size_type newsize); void <B><A HREF="#vector::resize">resize</A></B>(size_type newsize, Ty val); size_type <B><A HREF="#vector::size">size</A></B>() const; size_type <B><A HREF="#vector::max_size">max_size</A></B>() const; bool <B><A HREF="#vector::empty">empty</A></B>() const; Alloc <B><A HREF="#vector::get_allocator">get_allocator</A></B>() const; reference <B><A HREF="#vector::at">at</A></B>(size_type off); const_reference <B><A HREF="#vector::at">at</A></B>(size_type off) const; reference <B><A HREF="#vector::operator[]">operator[]</A></B>(size_type off); const_reference <B><A HREF="#vector::operator[]">operator[]</A></B>(size_type off); reference <B><A HREF="#vector::front">front</A></B>(); const_reference <B><A HREF="#vector::front">front</A></B>() const; reference <B><A HREF="#vector::back">back</A></B>(); const_reference <B><A HREF="#vector::back">back</A></B>() const; void <B><A HREF="#vector::push_back">push_back</A></B>(const Ty& val); void <B><A HREF="#vector::pop_back">pop_back</A></B>(); template<class InIt> void <B><A HREF="#vector::assign">assign</A></B>(InIt first, InIt last); void <B><A HREF="#vector::assign">assign</A></B>(size_type count, const Ty& val); iterator <B><A HREF="#vector::insert">insert</A></B>(iterator where, const Ty& val); void <B><A HREF="#vector::insert">insert</A></B>(iterator where, size_type count, const Ty& val); template<class InIt> void <B><A HREF="#vector::insert">insert</A></B>(iterator where, InIt first, InIt last); iterator <B><A HREF="#vector::erase">erase</A></B>(iterator where); iterator <B><A HREF="#vector::erase">erase</A></B>(iterator first, iterator last); void <B><A HREF="#vector::clear">clear</A></B>(); void <B><A HREF="#vector::swap">swap</A></B>(vector& right); };</PRE><P>The template class describes an object that controls avarying-length sequence of elements of type <CODE>Ty</CODE>.The sequence is stored as an array of <CODE>Ty</CODE>.</P><P>The object allocates and frees storage for the sequence it controlsthrough a stored <A HREF="memory.html#allocator object">allocator object</A>of class <CODE>Alloc</CODE>. Such an allocator object must havethe same external interface as an object of template class<A HREF="memory.html#allocator"><CODE>allocator</CODE></A>.Note that the stored allocator object is <I>not</I> copied when the containerobject is assigned.</P><P><B><A NAME="vector reallocation">Vector reallocation</A></B>occurs when a member function must grow the controlled sequencebeyond its current storage <A HREF="#vector::capacity">capacity</A>.Other insertions and erasures may alter various storage addresseswithin the sequence. In all such cases,iterators or references that point ataltered portions of the controlled sequence become<B><A NAME="invalid vector iterators">invalid</A></B>.</P><H3><CODE><A NAME="vector::allocator_type">vector::allocator_type</A></CODE></H3><PRE>typedef Alloc <B>allocator_type</B>;</PRE><P>The type is a synonym for the template parameter <CODE>Alloc</CODE>.</P>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -