📄 lis_3222.htm
字号:
<HTML><TITLE>list</TITLE><BODY>
<A HREF="ref.htm"><IMG SRC="images/banner.gif"></A>
<P><STRONG>Click on the banner to return to the Class Reference home page.</STRONG></P>
<P>©Copyright 1996 Rogue Wave Software</P>
<H2>list</H2>
<HR><PRE> Container</PRE><HR>
<A NAME="Summary"><H3>Summary</H3></A>
<P>A sequence that supports bidirectional iterators</P>
<H3>Contents</H3>
<UL>
<A HREF="#Synopsis"><LI>Synopsis</LI></A>
<A HREF="#Description"><LI>Description</LI></A>
<A HREF="#Interface"><LI>Interface</LI></A>
<A HREF="#Constructors and Destructors"><LI>Constructors and Destructors</LI></A>
<A HREF="#Assignment Operator"><LI>Assignment Operator</LI></A>
<A HREF="#Allocator"><LI>Allocator</LI></A>
<A HREF="#Iterators"><LI>Iterators</LI></A>
<A HREF="#Member Functions"><LI>Member Functions</LI></A>
<A HREF="#Non-member Operators"><LI>Non-member Operators</LI></A>
<A HREF="#Example"><LI>Example</LI></A>
<A HREF="#Warnings"><LI>Warnings</LI></A>
<A HREF="#See Also"><LI>See Also</LI></A>
</UL>
<A NAME="Synopsis"><H3>Synopsis</H3></A>
<PRE>#include <list></PRE>
<PRE>
template <class T, class Allocator = allocator>
class <B>list</B>;
</PRE>
<A NAME="Description"><H3>Description</H3></A>
<P><B><I>list<T,Allocator></B></I> is a type of sequence that supports bidirectional iterators. A <B><I>list<T,Allocator></B></I> allows constant time insert and erase operations anywhere within the sequence, with storage management handled automatically. Constant time random access is not supported. </P>
<P>Any type used for the template parameter <SAMP>T</SAMP> must provide the following (where <SAMP>T</SAMP> is the type, <SAMP>t</SAMP> is a <SAMP>value</SAMP> of <SAMP>T</SAMP> and <SAMP>u</SAMP> is a <SAMP>const</SAMP> <SAMP>value</SAMP> of <SAMP>T</SAMP>): </P>
<PRE> Default constructor T()</PRE>
<PRE> Copy constructors T(t) and T(u)
Destructor t.~T()
Address of &t and &u yielding T* and
const T* respectively
Assignment t = a where a is a
(possibly const) value of T</PRE>
<A NAME="Interface"><H3>Interface</H3></A>
<PRE>template <class T, class Allocator = allocator></PRE>
<PRE> class list {
public:
// typedefs
class iterator;
class const_iterator;
typename reference;
typename const_reference;
typename size_type;
typename difference_type;
typedef T value_type;
typedef Allocator allocator_type;
typename reverse_iterator;
typename const_reverse_iterator;
// Construct/Copy/Destroy
explicit list (const Allocator& = Allocator());
explicit list (size_type, const Allocator& = Allocator());
list (size_type, const T&, const Allocator& = Allocator())
template <class InputIterator>
list (InputIterator, InputIterator,
const Allocator& = Allocator());
list(const list<T, Allocator>& x);
~list();
list<T,Allocator>& operator= (const list<T,Allocator>&);
template <class InputIterator>
void assign (InputIterator, InputIterator);
template <class Size, class T>
void assign (Size n);
template <class Size, class T>
void assign (Size n, const T&);
allocator_type get allocator () const;
// Iterators
iterator begin ();
const_iterator begin () const;
iterator end ();
const_iterator end () const;
reverse_iterator rbegin ();
const_reverse_iterator rbegin () const;
reverse_iterator rend ();
const_reverse_iterator rend () const;
// Capacity
bool empty () const;
size_type size () const;
size_type max_size () const;
void resize (size_type);
void resize (size_type, T);
// Element Access
reference front ();
const_reference front () const;
reference back ();
const_reference back () const;
// Modifiers
void push_front (const T&);
void pop_front ();
void push_back (const T&);
void pop_back ();
iterator insert (iterator);
iterator insert (iterator, const T&);
void insert (iterator, size_type, const T&);
template <class InputIterator>
void insert (iterator, InputIterator, InputIterator);
iterator erase (iterator);
iterator erase (iterator, iterator);
void swap (list<T, Allocator>&);
void clear ();
// Special mutative operations on list
void splice (iterator, list<T, Allocator>&);
void splice (iterator, list<T, Allocator>&, iterator);
void splice (iterator, list<T, Allocator>&, iterator, iterator);
void remove (const T&);
template <class Predicate>
void remove_if (Predicate);
void unique ();
template <class BinaryPredicate>
void unique (BinaryPredicate);
void merge (list<T, Allocator>&);
template <class Compare>
void merge (list<T, Allocator>&, Compare);
void sort ();
template <class Compare>
void sort (Compare);
void reverse();
};
// Non-member List Operators
template <class T>
bool <B>operator==</B> (const list<T, Allocator>&,
const list<T, Allocator>&);
template <class T>
bool <B>operator<</B> (const list<T, Allocator>&,
const list<T, Allocator>&);
// Specialized Algorithms
template <class T, class Allocator>
void swap (list<T,Allocator>&, list<T, Allocator>&);
</PRE>
<A NAME="Constructors and Destructors"><H3>Constructors and Destructors</H3></A>
<PRE>explicit <B>list </B>(const Allocator& alloc = Allocator());</PRE>
<UL><P>Creates a list of zero elements. The list will use the allocator <SAMP>alloc</SAMP> for all storage management.</P>
</UL>
<PRE>explicit <B>list</B> (size_type n,
const Allocator& alloc = Allocator());</PRE>
<UL><P>Creates a list of length <SAMP>n</SAMP>, containing <SAMP>n</SAMP> copies of the default value for type <SAMP>T</SAMP>. Requires that <SAMP>T</SAMP> have a default constructor. The list will use the allocator <SAMP>alloc</SAMP> for all storage management. </P>
</UL>
<PRE><B>list</B> (size_type n, const T& value,
const Allocator& alloc = Allocator());</PRE>
<UL><P>Creates a list of length <SAMP>n</SAMP>, containing <SAMP>n</SAMP> copies of <SAMP>value</SAMP>. The list will use the allocator <SAMP>alloc</SAMP> for all storage management. </P>
</UL>
<PRE>template <class InputIterator>
<B>list</B> (InputIterator first, InputIterator last,
const Allocator& alloc = Allocator()); </PRE>
<UL><P>Creates a list of length <SAMP>last - first</SAMP>, filled with all values obtained by dereferencing the <SAMP>InputIterators</SAMP> on the range<SAMP> [first, last)</SAMP>. The list will use the allocator <SAMP>alloc</SAMP> for all storage management.</P>
</UL>
<PRE><B>list</B> (const list<T, Allocator>& x);</PRE>
<UL><P>Copy constructor. Creates a copy of <SAMP>x</SAMP>.</P>
</UL>
<PRE><B>~list</B> ();</PRE>
<UL><P>The destructor. Releases any allocated memory for this list.</P>
</UL>
<A NAME="Assignment Operator"><H3>Assignment Operator</H3></A>
<PRE>list<T, Allocator>& <B>operator= </B>(const list<T, Allocator>& x)</PRE>
<UL><P>Erases all elements in self then inserts into self a copy of each element in <SAMP>x</SAMP>. Returns a reference to <SAMP>*this</SAMP>.</P>
</UL>
<A NAME="Allocator"><H3>Allocator</H3></A>
<PRE>allocator_type <B>get_allocator</B> () const;</PRE>
<UL><P>Returns a copy of the allocator used by self for storage management.</P>
</UL>
<A NAME="Iterators"><H3>Iterators</H3></A>
<PRE>iterator <B>begin</B> ();</PRE>
<UL><P>Returns a bidirectional iterator that points to the first element.</P>
</UL>
<PRE>const_iterator <B>begin</B> () const;</PRE>
<UL><P>Returns a constant bidirectional iterator that points to the first element.</P>
</UL>
<PRE>iterator <B>end</B> ();</PRE>
<UL><P>Returns a bidirectional iterator that points to the past-the-end value.</P>
</UL>
<PRE>const_iterator <B>end</B> () const;</PRE>
<UL><P>Returns a constant bidirectional iterator that points to the past-the-end value.</P>
</UL>
<PRE>reverse_iterator <B>rbegin</B> ();</PRE>
<UL><P>Returns a bidirectional iterator that points to the past-the-end value.</P>
</UL>
<PRE>const_reverse_iterator <B>rbegin</B> () const;</PRE>
<UL><P>Returns a constant bidirectional iterator that points to the past-the-end value.</P>
</UL>
<PRE>reverse_iterator <B>rend</B> ();</PRE>
<UL><P>Returns a bidirectional iterator that points to the first element.</P>
</UL>
<PRE>const_reverse_iterator <B>rend</B> () const;</PRE>
<UL><P>Returns a constant bidirectional iterator that points to the first element.</P>
</UL>
<A NAME="Member Functions"><H3>Member Functions</H3></A>
<PRE>template <class InputIterator>
void
<B>assign</B> (InputIterator first, InputIterator last);</PRE>
<UL><P>Erases all elements contained in self, then inserts new elements from the range <SAMP>[first, last)</SAMP>.</P>
</UL>
<PRE>template <class Size, class T>
void
<B>assign</B> (Size n);</PRE>
<UL><P>Erases all elements contained in self, then inserts <SAMP>n</SAMP> instances of the default <SAMP>value</SAMP> of <SAMP>t.</SAMP></P>
</UL>
<PRE>template <class Size, class T>
void
<B>assign</B> (Size n, const T& t);</PRE>
<UL><P>Erases all elements contained in self, then inserts <SAMP>n</SAMP> instances of the <SAMP>value</SAMP> of <SAMP>t.</SAMP></P>
</UL>
<PRE>reference
<B>back</B> ();</PRE>
<UL><P>Returns a <SAMP>reference</SAMP> to the last element.</P>
</UL>
<PRE>const_reference
<B>back</B> () const;</PRE>
<UL><P>Returns a constant reference to the last element.</P>
</UL>
<PRE>void
<B>clear</B> ();</PRE>
<UL><P>Erases all elements from the list.</P>
</UL>
<PRE>bool
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -