📄 list.html
字号:
<HTML><HEAD><TITLE><list></TITLE></HEAD><BODY><H1><A NAME="<list>"><CODE><list></CODE></A></H1><HR><P>Include the <A HREF="index.html#STL">STL</A>standard header <B><CODE><list></CODE></B> to define the<A HREF="lib_cont.html#Containers">container</A>template class <CODE>list</CODE> and several supportingtemplates.</P><PRE>namespace std {template<class Ty, class Alloc> class <B><A HREF="#list">list</A></B>; // TEMPLATE FUNCTIONStemplate<class Ty, class Alloc> bool <B><A HREF="#operator==">operator==</A></B>( const list<Ty, Alloc>& left, const list<Ty, Alloc>& right);template<class Ty, class Alloc> bool <B><A HREF="#operator!=">operator!=</A></B>( const list<Ty, Alloc>& left, const list<Ty, Alloc>& right);template<class Ty, class Alloc> bool <B><A HREF="#operator<">operator<</A></B>( const list<Ty, Alloc>& left, const list<Ty, Alloc>& right);template<class Ty, class Alloc> bool <B><A HREF="#operator>">operator></A></B>( const list<Ty, Alloc>& left, const list<Ty, Alloc>& right);template<class Ty, class Alloc> bool <B><A HREF="#operator<=">operator<=</A></B>( const list<Ty, Alloc>& left, const list<Ty, Alloc>& right);template<class Ty, class Alloc> bool <B><A HREF="#operator>=">operator>=</A></B>( const list<Ty, Alloc>& left, const list<Ty, Alloc>& right);template<class Ty, class Alloc> void <B><A HREF="#swap">swap</A></B>( list<Ty, Alloc>& left, list<Ty, Alloc>& right); };</PRE><H2><A NAME="list"><CODE>list</CODE></A></H2><HR><P><B><CODE><A HREF="#list::allocator_type">allocator_type</A>· <A HREF="#list::assign">assign</A>· <A HREF="#list::back">back</A>· <A HREF="#list::begin">begin</A>· <A HREF="#list::clear">clear</A>· <A HREF="#list::const_iterator">const_iterator</A>· <A HREF="#list::const_pointer">const_pointer</A>· <A HREF="#list::const_reference">const_reference</A>· <A HREF="#list::const_reverse_iterator">const_reverse_iterator</A>· <A HREF="#list::difference_type">difference_type</A>· <A HREF="#list::empty">empty</A>· <A HREF="#list::end">end</A>· <A HREF="#list::erase">erase</A>· <A HREF="#list::front">front</A>· <A HREF="#list::get_allocator">get_allocator</A>· <A HREF="#list::insert">insert</A>· <A HREF="#list::iterator">iterator</A>· <A HREF="#list::list">list</A>· <A HREF="#list::max_size">max_size</A>· <A HREF="#list::merge">merge</A>· <A HREF="#list::pointer">pointer</A>· <A HREF="#list::pop_back">pop_back</A>· <A HREF="#list::pop_front">pop_front</A>· <A HREF="#list::push_back">push_back</A>· <A HREF="#list::push_front">push_front</A>· <A HREF="#list::rbegin">rbegin</A>· <A HREF="#list::reference">reference</A>· <A HREF="#list::remove">remove</A>· <A HREF="#list::remove_if">remove_if</A>· <A HREF="#list::rend">rend</A>· <A HREF="#list::resize">resize</A>· <A HREF="#list::reverse">reverse</A>· <A HREF="#list::reverse_iterator">reverse_iterator</A>· <A HREF="#list::size">size</A>· <A HREF="#list::size_type">size_type</A>· <A HREF="#list::sort">sort</A>· <A HREF="#list::splice">splice</A>· <A HREF="#list::swap">swap</A>· <A HREF="#list::unique">unique</A>· <A HREF="#list::value_type">value_type</A></CODE></B></P><HR><PRE>template<class Ty, class Alloc = allocator<Ty> > class <B>list</B> {public: typedef Alloc <B><A HREF="#list::allocator_type">allocator_type</A></B>; typedef typename Alloc::pointer <B><A HREF="#list::pointer">pointer</A></B>; typedef typename Alloc::const_pointer <B><A HREF="#list::const_pointer">const_pointer</A></B>; typedef typename Alloc::reference <B><A HREF="#list::reference">reference</A></B>; typedef typename Alloc::const_reference <B><A HREF="#list::const_reference">const_reference</A></B>; typedef typename Alloc::value_type <B><A HREF="#list::value_type">value_type</A></B>; typedef T0 <B><A HREF="#list::iterator">iterator</A></B>; typedef T1 <B><A HREF="#list::const_iterator">const_iterator</A></B>; typedef T2 <B><A HREF="#list::size_type">size_type</A></B>; typedef T3 <B><A HREF="#list::difference_type">difference_type</A></B>; typedef reverse_iterator<const_iterator> <B><A HREF="#list::const_reverse_iterator">const_reverse_iterator</A></B>; typedef reverse_iterator<iterator> <B><A HREF="#list::reverse_iterator">reverse_iterator</A></B>; <B><A HREF="#list::list">list</A></B>(); explicit <B><A HREF="#list::list">list</A></B>(const Alloc& al); explicit <B><A HREF="#list::list">list</A></B>(size_type count); <B><A HREF="#list::list">list</A></B>(size_type count, const Ty& val); <B><A HREF="#list::list">list</A></B>(size_type count, const Ty& val, const Alloc& al); <B><A HREF="#list::list">list</A></B>(const list& right); template<class InIt> <B><A HREF="#list::list">list</A></B>(InIt first, InIt last); template<class InIt> <B><A HREF="#list::list">list</A></B>(InIt first, InIt last, const Alloc& al); iterator <B><A HREF="#list::begin">begin</A></B>(); const_iterator <B><A HREF="#list::begin">begin</A></B>() const; iterator <B><A HREF="#list::end">end</A></B>(); const_iterator <B><A HREF="#list::end">end</A></B>() const; reverse_iterator <B><A HREF="#list::rbegin">rbegin</A></B>(); const_reverse_iterator <B><A HREF="#list::rbegin">rbegin</A></B>() const; reverse_iterator <B><A HREF="#list::rend">rend</A></B>(); const_reverse_iterator <B><A HREF="#list::rend">rend</A></B>() const; void <B><A HREF="#list::resize">resize</A></B>(size_type newsize); void <B><A HREF="#list::resize">resize</A></B>(size_type newsize, Ty val); size_type <B><A HREF="#list::size">size</A></B>() const; size_type <B><A HREF="#list::max_size">max_size</A></B>() const; bool <B><A HREF="#list::empty">empty</A></B>() const; Alloc <B><A HREF="#list::get_allocator">get_allocator</A></B>() const; reference <B><A HREF="#list::front">front</A></B>(); const_reference <B><A HREF="#list::front">front</A></B>() const; reference <B><A HREF="#list::back">back</A></B>(); const_reference <B><A HREF="#list::back">back</A></B>() const; void <B><A HREF="#list::push_front">push_front</A></B>(const Ty& val); void <B><A HREF="#list::pop_front">pop_front</A></B>(); void <B><A HREF="#list::push_back">push_back</A></B>(const Ty& val); void <B><A HREF="#list::pop_back">pop_back</A></B>(); template<class InIt> void <B><A HREF="#list::assign">assign</A></B>(InIt first, InIt last); void <B><A HREF="#list::assign">assign</A></B>(size_type count, const Ty& val); iterator <B><A HREF="#list::insert">insert</A></B>(iterator where, const Ty& val); void <B><A HREF="#list::insert">insert</A></B>(iterator where, size_type count, const Ty& val); template<class InIt> void <B><A HREF="#list::insert">insert</A></B>(iterator where, InIt first, InIt last); iterator <B><A HREF="#list::erase">erase</A></B>(iterator where); iterator <B><A HREF="#list::erase">erase</A></B>(iterator first, iterator last); void <B><A HREF="#list::clear">clear</A></B>(); void <B><A HREF="#list::swap">swap</A></B>(list& right); void <B><A HREF="#list::splice">splice</A></B>(iterator where, list& right); void <B><A HREF="#list::splice">splice</A></B>(iterator where, list& right, iterator first); void <B><A HREF="#list::splice">splice</A></B>(iterator where, list& right, iterator first, iterator last); void <B><A HREF="#list::remove">remove</A></B>(const Ty& val); templace<class Pr1> void <B><A HREF="#list::remove_if">remove_if</A></B>(Pr1 pred); void <B><A HREF="#list::unique">unique</A></B>(); template<class Pr2> void <B><A HREF="#list::unique">unique</A></B>(Pr2 pred); void <B><A HREF="#list::merge">merge</A></B>(list& right); template<class Pr3> void <B><A HREF="#list::merge">merge</A></B>(list& right, Pr3 pred); void <B><A HREF="#list::sort">sort</A></B>(); template<class Pr3> void <B><A HREF="#list::sort">sort</A></B>(Pr3 pred); void <B><A HREF="#list::reverse">reverse</A></B>(); };</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 a bidirectional linked list of elements,each containing a member of type <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="list reallocation">List reallocation</A></B>occurs when a member function must insert, erase, or splice elements ofthe controlled sequence. In all such cases, only iteratorsor references that designate erased or spliced elemetsof the controlled sequence become<B><A NAME="invalid list iterators">invalid</A></B>.</P><P>All additions to the controlled sequence occur as if by calls to<CODE><A HREF="#list::insert">insert</A></CODE>, which is theonly member function that calls the constructor<CODE>Ty(const Ty&)</CODE>. If such an expression throwsan exception, the container object inserts no new elements and rethrowsthe exception. Thus, an object of template class <CODE>list</CODE>is left in a known state when such exceptions occur.</P><H3><CODE><A NAME="list::allocator_type">list::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><H3><CODE><A NAME="list::assign">list::assign</A></CODE></H3><PRE>template<class InIt> void <B>assign</B>(InIt first, InIt last);void <B>assign</B>(size_type count, const Ty& val);</PRE><P>If <CODE>InIt</CODE> is an integer type, the first memberfunction behaves the same as <CODE>assign((size_type)first, (Ty)last)</CODE>.Otherwise, thefirst member function replaces the sequencecontrolled by <CODE>*this</CODE> with the sequence<CODE>[first, last)</CODE>, which must <I>not</I> overlapthe initial controlled sequence.The second member function replaces the sequencecontrolled by <CODE>*this</CODE> with a repetition of <CODE>count</CODE>elements of value <CODE>val</CODE>.</P><H3><CODE><A NAME="list::back">list::back</A></CODE></H3><PRE>reference <B>back</B>();const_reference <B>back</B>() const;</PRE><P>The member function returns a reference to the last element of thecontrolled sequence, which must be non-empty.</P><H3><CODE><A NAME="list::begin">list::begin</A></CODE></H3><PRE>const_iterator <B>begin</B>() const;iterator <B>begin</B>();</PRE><P>The member function returns a bidirectional iterator that points atthe first element of the sequence (or just beyond the end of an emptysequence).</P><H3><CODE><A NAME="list::clear">list::clear</A></CODE></H3><PRE>void <B>clear</B>();</PRE><P>The member function calls<CODE><A HREF="#list::erase">erase</A>(<A HREF="#list::begin">begin</A>(),<A HREF="#list::end">end</A>())</CODE>.</P><H3><CODE><A NAME="list::const_iterator">list::const_iterator</A></CODE></H3><PRE>typedef T1 <B>const_iterator</B>;</PRE><P>The type describes an object that can serve as a constantbidirectional iterator for the controlled sequence.It is described here as asynonym for the implementation-defined type <CODE>T1</CODE>.</P><H3><CODE><A NAME="list::const_pointer">list::const_pointer</A></CODE></H3><PRE>typedef typename Alloc::const_pointer <B>const_pointer</B>;</PRE><P>The type describes an object that can serve as a constant pointer
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -