?? slist.html
字號:
<P>The member function returns an iterator that designates the elementimmediately preceding <CODE>it</CODE>, if possible; otherwise it returns<CODE><A HREF="#slist::end">end</A>()</CODE>.This operation takes time proportional to the number of elementsin the controlled sequence (linear time complexity).</P><H3><CODE><A NAME="slist::push_back">slist::push_back</A></CODE></H3><PRE>void <B>push_back</B>(const T& x);</PRE><P>The member function inserts an element with value <CODE>x</CODE>at the end of the controlled sequence.</P><P>If an exception is thrown, the container is left unalteredand the exception is rethrown.</P><H3><CODE><A NAME="slist::push_front">slist::push_front</A></CODE></H3><PRE>void <B>push_front</B>(const T& x);</PRE><P>The member function inserts an element with value <CODE>x</CODE>at the beginning of the controlled sequence.</P><P>If an exception is thrown, the container is left unalteredand the exception is rethrown.</P><H3><CODE><A NAME="slist::reference">slist::reference</A></CODE></H3><PRE>typedef typename A::reference <B>reference</B>;</PRE> <P>The type describes an object that can serve as a reference to anelement of the controlled sequence.</P> <H3><CODE><A NAME="slist::remove">slist::remove</A></CODE></H3><PRE>void <B>remove</B>(const T& x);</PRE><P>The member function removes from the controlled sequenceall elements, designated by the iterator <CODE>P</CODE>, for which<CODE>*P == x</CODE>.</P><P>The member function never throws an exception.</P><H3><CODE><A NAME="slist::remove_if">slist::remove_if</A></CODE></H3><PRE>templace<class Pred> void <B>remove_if</B>(Pred pr);</PRE><P>The member function removes from the controlled sequenceall elements, designated by the iterator <CODE>P</CODE>, for which<CODE>pr(*P)</CODE> is true.</P><P>An exception occurs only if <CODE>pr</CODE> throws an exception.In that case, the controlled sequence is left in an unspecified stateand the exception is rethrown.</P><H3><CODE><A NAME="slist::resize">slist::resize</A></CODE></H3><PRE>void <B>resize</B>(size_type n);void <B>resize</B>(size_type n, T x);</PRE> <P>The member functions both ensure that<CODE><A HREF="#slist::size">size</A>()</CODE> henceforthreturns <CODE>n</CODE>. If it must make the controlled sequence longer,the first member functionappends elements with value <CODE>T()</CODE>, while the second member function appends elements with value <CODE>x</CODE>.To make the controlled sequence shorter, both member functions call<CODE><A HREF="#slist::erase">erase</A>(begin() + n, end())</CODE>.</P> <H3><CODE><A NAME="slist::reverse">slist::reverse</A></CODE></H3><PRE>void <B>reverse</B>();</PRE><P>The member function reverses the order in which elements appearin the controlled sequence.</P><H3><CODE><A NAME="slist::size">slist::size</A></CODE></H3><PRE>size_type <B>size</B>() const;</PRE> <P>The member function returns the length of the controlled sequence.</P> <H3><CODE><A NAME="slist::size_type">slist::size_type</A></CODE></H3><PRE>typedef T2 <B>size_type</B>;</PRE> <P>The unsigned integer type describes an object that can represent thelength of any controlled sequence. It is described here as asynonym for the implementation-defined type <CODE>T2</CODE>.</P> <H3><CODE><A NAME="slist::slist">slist::slist</A></CODE></H3><PRE><B>slist</B>();explicit <B>slist</B>(const A& al);explicit <B>slist</B>(size_type n);<B>slist</B>(size_type n, const T& v);<B>slist</B>(size_type n, const T& v, const A& al);<B>slist</B>(const slist& x);template<class InIt> <B>slist</B>(InIt first, InIt last);template<class InIt> <B>slist</B>(InIt first, InIt last, const A& al);</PRE><P>All constructors store an<A HREF="memory.html#allocator object">allocator object</A> andinitialize the controlled sequence. The allocator object is the argument<CODE>al</CODE>, if present. For the copy constructor, it is<CODE>x.<A HREF="#slist::get_allocator">get_allocator</A>()</CODE>.Otherwise, it is <CODE>A()</CODE>.</P><P>The first two constructors specify anempty initial controlled sequence. The third constructor specifiesa repetition of <CODE>n</CODE> elements of value <CODE>T()</CODE>.The fourth and fifth constructors specifya repetition of <CODE>n</CODE> elements of value <CODE>x</CODE>.The sixth constructor specifies a copy of the sequence controlled by<CODE>x</CODE>.If <CODE>InIt</CODE> is an integer type, the last two constructorsspecify a repetition of <CODE>(size_type)first</CODE> elements of value<CODE>(T)last</CODE>. Otherwise, thelast two constructors specify the sequence<CODE>[first, last)</CODE>.</P><H3><CODE><A NAME="slist::sort">slist::sort</A></CODE></H3><PRE>void <B>sort</B>();template<class Pred> void <B>sort</B>(Pred pr);</PRE><P>Both member functions order the elements in the controlledsequence by a predicate, described below.</P><P>For the iterators <CODE>Pi</CODE> and <CODE>Pj</CODE>designating elements at positions <CODE>i</CODE>and <CODE>j</CODE>, the first member function imposes theorder <CODE>!(*Pj < *Pi)</CODE> whenever <CODE>i < j</CODE>.(The elements are sorted in <I>ascending</I> order.)The member template function imposes the order<CODE>!pr(*Pj, *Pi)</CODE> whenever <CODE>i < j</CODE>.No ordered pairs of elements in the original controlled sequenceare reversed in the resulting controlled sequence.(The sort is stable.)</P><P>An exception occurs only if <CODE>pr</CODE> throws an exception.In that case, the controlled sequence is left in unspecified orderand the exception is rethrown.</P><H3><CODE><A NAME="slist::splice">slist::splice</A></CODE></H3><PRE>void <B>splice</B>(iterator it, slist& x);void <B>splice</B>(iterator it, slist& x, iterator first);void <B>splice</B>(iterator it, slist& x, iterator first, iterator last);</PRE><P>The first member function inserts the sequence controlledby <CODE>x</CODE> before the element in the controlled sequencepointed to by <CODE>it</CODE>. It also removes all elements from<CODE>x</CODE>. (<CODE>&x</CODE> must not equal <CODE>this</CODE>.)</P><P>The second member function removes the element pointed to by<CODE>first</CODE> in the sequence controlled by <CODE>x</CODE> andinserts it before the element in the controlled sequencepointed to by <CODE>it</CODE>. (If <CODE>it == first || it == ++first</CODE>,no change occurs.)</P><P>The third member function inserts the subrangedesignated by <CODE>[first, last)</CODE> from the sequencecontrolled by <CODE>x</CODE>before the element in the controlled sequence pointed to by <CODE>it</CODE>.It also removes the original subrange from the sequence controlledby <CODE>x</CODE>. (If <CODE>&x == this</CODE>,the range <CODE>[first, last)</CODE> must not include the elementpointed to by <CODE>it</CODE>.)</P><P>If the third member function inserts<CODE>N</CODE> elements, and <CODE>&x != this</CODE>, an object of class<CODE><A HREF="#slist::iterator">iterator</A></CODE> isincremented <CODE>N</CODE> times.For all <CODE>splice</CODE> member functions, If<CODE><A HREF="#slist::get_allocator">get_allocator</A>()== str.get_allocator()</CODE>, no exception occurs.Otherwise, a copy and a destructor call alsooccur for each inserted element.</P><P>Iterators or references that designatespliced elements, or that designate the first element beyond asequence of spliced elements, become<B><A NAME="invalid slist iterators">invalid</A></B>.</P><H3><CODE><A NAME="slist::swap">slist::swap</A></CODE></H3><PRE>void <B>swap</B>(slist& x);</PRE> <P>The member function swaps the controlled sequences between<CODE>*this</CODE> and <CODE>x</CODE>. If<CODE><A HREF="#slist::get_allocator">get_allocator</A>()== x.get_allocator()</CODE>, it does so in constant time,it throws no exceptions, and it invalidates no references, pointers,or iterators that designate elements in the two controlled sequences.Otherwise, it performs a number of element assignments and constructor callsproportional to the number of elements in the two controlled sequences.</P> <H3><CODE><A NAME="slist::unique">slist::unique</A></CODE></H3><PRE>void <B>unique</B>();template<class Pred> void <B><A HREF="#slist::unique">unique</A></B>(Pred pr);</PRE><P>The first member function removes from the controlled sequenceevery element that compares equal to its preceding element.For the iterators <CODE>Pi</CODE> and <CODE>Pj</CODE>designating elements at positions <CODE>i</CODE>and <CODE>j</CODE>, the second member function removes everyelement for which <CODE>i + 1 == j && pr(*Pi, *Pj)</CODE>.</P><P>For a controlled sequence of length <CODE>N</CODE>(> 0), the predicate <CODE>pr(*Pi, *Pj)</CODE>is evaluated <CODE>N - 1</CODE> times.</P><P>An exception occurs only if <CODE>pr</CODE> throws an exception.In that case, the controlled sequence is left in an unspecified stateand the exception is rethrown.</P><H3><CODE><A NAME="slist::value_type">slist::value_type</A></CODE></H3><PRE>typedef typename A::value_type <B>value_type</B>;</PRE> <P>The type is a synonym for the template parameter <CODE>T</CODE>.</P> <H2><A NAME="swap"><CODE>swap</CODE></A></H2> <PRE>template<class T, class A> void <B>swap</B>( slist <T, A>& lhs, slist <T, A>& rhs);</PRE> <P>The template function executes<CODE>lhs.<A HREF="#slist::swap">swap</A>(rhs)</CODE>.</P><HR><P>See also the<B><A HREF="index.html#Table of Contents">Table of Contents</A></B> and the<B><A HREF="_index.html">Index</A></B>.</P><P><I><A HREF="crit_pjp.html">Copyright</A> © 1999-2002 by P.J. Plauger.All rights reserved.</I></P><!--V4.01:1125--></BODY></HTML>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -