📄 iterator.html
字号:
<P>The type is a synonym for<CODE>basic_istream<Elem,Tr></CODE>.</P><H3><A NAME="istreambuf_iterator::istreambuf_iterator"><CODE>istreambuf_iterator::istreambuf_iterator</CODE></A></H3><PRE><B>istreambuf_iterator</B>(streambuf_type *strbuf = 0) throw();<B>istreambuf_iterator</B>(istream_type& istr) throw();</PRE><P>The first constructor initializes the input stream-buffer pointerwith <CODE>strbuf</CODE>.The second constructor initializes the input stream-buffer pointer with<CODE>istr.rdbuf()</CODE>,then (eventually) attempts to extract and storean object of type <CODE>Elem</CODE>.</P><H3><A NAME="istreambuf_iterator::operator*"><CODE>istreambuf_iterator::operator*</CODE></A></H3><PRE>Elem <B>operator*</B>() const;</PRE><P>The operator returns the stored object of type <CODE>Elem</CODE>.</P><H3><A NAME="istreambuf_iterator::operator++"><CODE>istreambuf_iterator::operator++</CODE></A></H3><PRE>istreambuf_iterator& <B>operator++</B>();istreambuf_iterator <B>operator++</B>(int);</PRE><P>The first operator (eventually) attempts to extract and store an objectof type <CODE>Elem</CODE> from the associated input stream. The secondoperator makes a copy of the object, increments the object, thenreturns the copy.</P><H3><A NAME="istreambuf_iterator::streambuf_type"><CODE>istreambuf_iterator::streambuf_type</CODE></A></H3><PRE>typedef basic_streambuf<Elem, Tr> <B>streambuf_type</B>;</PRE><P>The type is a synonym for<CODE>basic_streambuf<Elem,Tr></CODE>.</P><H3><A NAME="istreambuf_iterator::traits_type"><CODE>istreambuf_iterator::traits_type</CODE></A></H3><PRE>typedef Tr <B>traits_type</B>;</PRE><P>The type is a synonym for the template parameter <CODE>Tr</CODE>.</P><H2><A NAME="iterator"><CODE>iterator</CODE></A></H2><PRE>template<class Category, class Ty, class Diff = ptrdiff_t class Pointer = Ty *, class Reference = Ty&> struct <B>iterator</B> { typedef Category <B>iterator_category</B>; typedef Ty <B>value_type</B>; typedef Diff <B>difference_type</B>; typedef Pointer <B>pointer</B>; typedef Reference <B>reference</B>; };</PRE><P>The template class can serve as a convenient base classfor an iterator class that you define.It defines the member types<CODE><A NAME="iterator::iterator_category">iterator_category</A></CODE>(a synonym for the template parameter <CODE>Category</CODE>),<CODE><A NAME="iterator::value_type">value_type</A></CODE>(a synonym for the template parameter <CODE>Ty</CODE>),<CODE><A NAME="iterator::difference_type">difference_type</A></CODE>(a synonym for the template parameter <CODE>Diff</CODE>),<CODE><A NAME="iterator::pointer">pointer</A></CODE>(a synonym for the template parameter <CODE>Pointer</CODE>), and<CODE><A NAME="iterator::reference">reference</A></CODE>(a synonym for the template parameter <CODE>Reference</CODE>).</P><P>Note that <CODE>value_type</CODE> should <I>not</I> be a constanttype even if <CODE>pointer</CODE> points at an object of const typeand <CODE>reference</CODE> designates an object of const type.</P><H2><A NAME="iterator_traits"><CODE>iterator_traits</CODE></A></H2><PRE>template<class Iter> struct <B>iterator_traits</B> { typedef typename Iter::iterator_category <B>iterator_category</B>; typedef typename Iter::value_type <B>value_type</B>; typedef typename Iter::difference_type <B>difference_type</B>; typedef typename Iter::pointer <B>pointer</B>; typedef typename Iter::reference <B>reference</B>; };template<class Ty> struct <B>iterator_traits</B><Ty *> { typedef random_access_iterator_tag <B>iterator_category</B>; typedef Ty <B>value_type</B>; typedef ptrdiff_t <B>difference_type</B>; typedef Ty *<B>pointer</B>; typedef Ty& <B>reference</B>; };template<class Ty> struct <B>iterator_traits</B><const Ty *> { typedef random_access_iterator_tag <B>iterator_category</B>; typedef Ty <B>value_type</B>; typedef ptrdiff_t <B>difference_type</B>; typedef const Ty *<B>pointer</B>; typedef const Tr& <B>reference</B>; };</PRE><P>The template class determines several critical types associatedwith the iterator type <CODE>Iter</CODE>.It defines the member types<CODE><A NAME="iterator_traits::iterator_category">iterator_category</A></CODE>(a synonym for <CODE>Iter::iterator_category</CODE>),<CODE><A NAME="iterator_traits::value_type">value_type</A></CODE>(a synonym for <CODE>Iter::value_type</CODE>),<CODE><A NAME="iterator_traits::difference_type">difference_type</A></CODE>(a synonym for <CODE>Iter::difference_type</CODE>),<CODE><A NAME="iterator_traits::pointer">pointer</A></CODE>(a synonym for <CODE>Iter::pointer</CODE>), and<CODE><A NAME="iterator_traits::reference">reference</A></CODE>(a synonym for <CODE>Iter::reference</CODE>).</P><P>The partial specializations determine the critical types associatedwith an object pointer type <CODE>Ty *</CODE> or <CODE>const Ty *</CODE>. In this<A HREF="index.html#implementation">implementation</A>,you can also use several template functions that do not make use ofpartial specialization:</P><PRE>template<class Category, class Ty, class Diff> C <B><A NAME="_Iter_cat">_Iter_cat</A></B>(const iterator<Category, Ty, Diff>&);template<class Ty> random_access_iterator_tag <B>_Iter_cat</B>(const Ty *);template<class Category, class Ty, class Diff> Ty *<B><A NAME="_Val_type">_Val_type</A></B>(const iterator<Category, Ty, Diff>&);template<class Ty> Ty *<B>_Val_type</B>(const Ty *);template<class Category, class Ty, class Diff> Diff *<B><A NAME="_Dist_type">_Dist_type</A></B>(const iterator<Category, Ty, Diff>&);template<class Ty> ptrdiff_t *<B>_Dist_type</B>(const Ty *);</PRE><P>which determine several of the same types a bit more indirectly.You use these functions as argumentson a function call. Their sole purpose is to supply a useful templateclass parameter to the called function.</P><H2><A NAME="operator!="><CODE>operator!=</CODE></A></H2><PRE>template<class RanIt> bool <B>operator!=</B>( const reverse_iterator<RanIt>& left, const reverse_iterator<RanIt>& right);template<class Ty, class Elem, class Tr, class Diff> bool <B>operator!=</B>( const istream_iterator<Ty, Elem, Tr, Diff>& left, const istream_iterator<Ty, Elem, Tr, Diff>& right);template<class Elem, class Tr> bool <B>operator!=</B>( const istreambuf_iterator<Elem, Tr>& left, const istreambuf_iterator<Elem, Tr>& right);</PRE><P>The template operator returns <CODE>!(left == right)</CODE>.</P><H2><A NAME="operator=="><CODE>operator==</CODE></A></H2><PRE>template<class RanIt> bool <B>operator==</B>( const reverse_iterator<RanIt>& left, const reverse_iterator<RanIt>& right);template<class Ty, class Elem, class Tr, class Diff> bool <B>operator==</B>( const istream_iterator<Ty, Elem, Tr, Diff>& left, const istream_iterator<Ty, Elem, Tr, Diff>& right);template<class Elem, class Tr> bool <B>operator==</B>( const istreambuf_iterator<Elem, Tr>& left, const istreambuf_iterator<Elem, Tr>& right);</PRE><P>The first template operator returns true only if<CODE>left.<A HREF="#reverse_iterator::current">current</A> ==right.current</CODE>. The second template operator returns true onlyif both <CODE>left</CODE> and <CODE>right</CODE> store the samestream pointer. The third template operator returns<CODE>left.<A HREF="#istreambuf_iterator::equal">equal</A>(right)</CODE>.</P><H2><A NAME="operator<"><CODE>operator<</CODE></A></H2><PRE>template<class RanIt> bool <B>operator<</B>( const reverse_iterator<RanIt>& left, const reverse_iterator<RanIt>& right);</PRE><P>The template operator returns<CODE>right.<A HREF="#reverse_iterator::current">current</A> <left.current</CODE> [sic].</P><H2><A NAME="operator<="><CODE>operator<=</CODE></A></H2><PRE>template<class RanIt> bool <B>operator<=</B>( const reverse_iterator<RanIt>& left, const reverse_iterator<RanIt>& right);</PRE><P>The template operator returns <CODE>!(right < left)</CODE>.</P><H2><A NAME="operator>"><CODE>operator></CODE></A></H2><PRE>template<class RanIt> bool <B>operator></B>( const reverse_iterator<RanIt>& left, const reverse_iterator<RanIt>& right);</PRE><P>The template operator returns <CODE>right < left</CODE>.</P><H2><A NAME="operator>="><CODE>operator>=</CODE></A></H2><PRE>template<class RanIt> bool <B>operator>=</B>( const reverse_iterator<RanIt>& left, const reverse_iterator<RanIt>& right);</PRE><P>The template operator returns <CODE>!(left < right)</CODE>.</P><H2><A NAME="operator+"><CODE>operator+</CODE></A></H2><PRE>template<class RanIt> reverse_iterator<RanIt> <B>operator+</B>(Diff off, const reverse_iterator<RanIt>& right);</PRE><P>The template operator returns <CODE>right + off</CODE>.</P><H2><A NAME="operator-"><CODE>operator-</CODE></A></H2><PRE>template<class RanIt> Diff <B>operator-</B>( const reverse_iterator<RanIt>& left, const reverse_iterator<RanIt>& right);</PRE><P>The template operator returns<CODE>right.<A HREF="#reverse_iterator::current">current</A> -left.current</CODE> [sic].</P><H2><A NAME="ostream_iterator"><CODE>ostream_iterator</CODE></A></H2><PRE>template<class Ty, class Elem = char, class Tr = char_traits<Elem> > class <B>ostream_iterator</B> : public iterator<output_iterator_tag, void, void, void, void> {public: typedef Elem <B><A HREF="#ostream_iterator::char_type">char_type</A></B>; typedef Tr <B><A HREF="#ostream_iterator::traits_type">traits_type</A></B>; typedef basic_ostream<Elem, Tr> <B><A HREF="#ostream_iterator::ostream_type">ostream_type</A></B>; <B><A HREF="#ostream_iterator::ostream_iterator">ostream_iterator</A></B>(ostream_type& ostr); <B><A HREF="#ostream_iterator::ostream_iterator">ostream_iterator</A></B>(ostream_type& ostr, const Elem *delim); ostream_iterator<Ty, Elem, Tr>& <B><A HREF="#ostream_iterator::operator=">operator=</A></B>(const Ty& val); ostream_iterator<Ty, Elem, Tr>& <B><A HREF="#ostream_iterator::operator*">operator*</A></B>(); ostream_iterator<Ty, Elem, Tr>& <B><A HREF="#ostream_iterator::operator++">operator++</A></B>(); ostream_iterator<Ty, Elem, Tr> <B><A HREF="#ostream_iterator::operator++">operator++</A></B>(int); };</PRE><P>The template class describes an output iterator object.It inserts objects of class <B><CODE>Ty</CODE></B>into an <B>output stream</B>, which it accesses via an object it stores,of type pointer to<CODE>basic_ostream<Elem, Tr></CODE>.It also stores a pointer to a <B>delimiter string</B>, anull-terminated stringof elements of type <CODE>Elem</CODE>, which is appended aftereach insertion. (Note that the string itself is <I>not</I> copiedby the constructor.</P><H3><A NAME="ostream_iterator::char_type"><CODE>ostream_iterator::char_type</CODE></A></H3><PRE>typedef Elem <B>char_type</B>;</PRE><P>The type is a synonym for the template parameter <CODE>Elem</CODE>.</P><H3><A NAME="ostream_iterator::operator*"><CODE>ostream_iterator::operator*</CODE></A></H3><PRE>ostream_iterator<Ty, Elem, Tr>& <B>operator*</B>();</PRE><P>The operator returns <CODE>*this</CODE>.</P><H3><A NAME="ostream_iterator::operator++"><CODE>ostream_iterator::operator++</CODE></A></H3><PRE>ostream_iterator<Ty, Elem, Tr>& <B>operator++</B>();ostream_iterator<Ty, Elem, Tr> <B>operator++</B>(int);</PRE><P>The operators both return <CODE>*this</CODE>.</P><H3><A NAME="ostream_iterator::operator="><CODE>ostream_iterator::operator=</CODE></A></H3><PRE>ostream_iterator<Ty, Elem, Tr>& <B>operator=</B>(const Ty& val);</PRE><P>The operator inserts <CODE>val</CODE> into theoutput stream associated with the object,then returns <CODE>*this</CODE>.</P><H3><A NAME="ostream_iterator::ostream_iterator"><CODE>ostream_iterator::ostream_iterator</CODE></A></H3><PRE><B>ostream_iterator</B>(ostream_type& ostr);<B>ostream_iterator</B>(ostream_type& ostr, const Elem *delim);</PRE><P>The first constructor initializes the output stream pointerwith <CODE>&ostr</CODE>. The delimiter string pointer designates anempty string. The second constructor initializes the output streampointer with <CODE>&ostr</CODE> and the delimiter string pointerwith <CODE>delim</CODE>.</P><H3><A NAME="ostream_iterator::ostream_type"><CODE>ostream_iterator::ostream_type</CODE></A></H3><PRE>typedef basic_ostream<Elem, Tr> <B>ostream_type</B>;</PRE><P>The type is a synonym for<CODE>basic_ostream<Elem, Tr></CODE>.</P><H3><A NAME="ostream_iterator::traits_type"><CODE>ostream_iterator::traits_type</CODE></A></H3><PRE>typedef Tr <B>traits_type</B>;</PRE><P>The type is a synonym for the template parameter <CODE>Tr</CODE>.</P>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -