146 lines
7.5 KiB
HTML
146 lines
7.5 KiB
HTML
<!--
|
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
|
contributor license agreements. See the NOTICE file distributed
|
|
with this work for additional information regarding copyright
|
|
ownership. The ASF licenses this file to you under the Apache
|
|
License, Version 2.0 (the License); you may not use this file
|
|
except in compliance with the License. You may obtain a copy of
|
|
the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
implied. See the License for the specific language governing
|
|
permissions and limitations under the License.
|
|
|
|
Copyright 1999-2007 Rogue Wave Software, Inc.
|
|
-->
|
|
|
|
<HTML>
|
|
<HEAD>
|
|
<TITLE>Insert Iterators</TITLE>
|
|
<LINK REL=StyleSheet HREF="../rw.css" TYPE="text/css" TITLE="Apache stdcxx Stylesheet"></HEAD>
|
|
<BODY BGCOLOR=#FFFFFF>
|
|
<A HREF="inputiterators.html"><IMG SRC="images/bprev.gif" WIDTH=20 HEIGHT=21 ALT="Previous file" BORDER=O></A><A HREF="noframes.html"><IMG SRC="images/btop.gif" WIDTH=56 HEIGHT=21 ALT="Top of Document" BORDER=O></A><A HREF="booktoc.html"><IMG SRC="images/btoc.gif" WIDTH=56 HEIGHT=21 ALT="Contents" BORDER=O></A><A HREF="tindex.html"><IMG SRC="images/bindex.gif" WIDTH=56 HEIGHT=21 ALT="Index page" BORDER=O></A><A HREF="insert-iterator.html"><IMG SRC="images/bnext.gif" WIDTH=25 HEIGHT=21 ALT="Next file" BORDER=O></A><DIV CLASS="DOCUMENTNAME"><B>Apache C++ Standard Library Reference Guide</B></DIV>
|
|
<H2>Insert Iterators</H2>
|
|
<P><B>Library:</B> <A HREF="2-8.html">Iterators</A></P>
|
|
|
|
<PRE><HR><B><I><A HREF="insert-iterator.html">insert_iterator</A></I></B> <IMG SRC="images/inherits.gif"> <B><I><A HREF="iterator.html">iterator</A></I></B><HR></PRE>
|
|
|
|
<UL>
|
|
<LI><A HREF="#sec1">Local Index</A></LI>
|
|
<LI><A HREF="#sec2">Summary</A></LI>
|
|
<LI><A HREF="#sec3">Synopsis</A></LI>
|
|
<LI><A HREF="#sec4">Description</A></LI>
|
|
<LI><A HREF="#sec5">Interface</A></LI>
|
|
<LI><A HREF="#sec6">See Also</A></LI>
|
|
<LI><A HREF="#sec7">Standards Conformance</A></LI>
|
|
</UL>
|
|
<A NAME="sec1"><H3>Local Index</H3></A>
|
|
No Entries
|
|
<A NAME="sec2"><H3>Summary</H3></A>
|
|
<P>An iterator adaptor that allows an iterator to insert into a container rather than overwrite elements in the container</P>
|
|
<A NAME="sec3"><H3>Synopsis</H3></A>
|
|
|
|
<PRE>#include <iterator>
|
|
|
|
namespace std {
|
|
template <class Container>
|
|
class insert_iterator;
|
|
|
|
template <class Container>
|
|
class back_insert_iterator;
|
|
|
|
template <class Container>
|
|
class front_insert_iterator;
|
|
}
|
|
</PRE>
|
|
<A NAME="sec4"><H3>Description</H3></A>
|
|
<P>Insert iterators are iterator adaptors that let an iterator <I>insert</I> new elements into a collection rather than overwrite existing elements when copying to a container. There are several types of insert iterator classes.</P>
|
|
<UL>
|
|
<LI><P CLASS="LIST">The class <B><I><A HREF="back-insert-iterator.html">back_insert_iterator</A></I></B> is used to insert items at the end of a collection. The function <SAMP><A HREF="back-insert-iterator.html">back_inserter()</A></SAMP> can be used with an iterator inline, to create an instance of a <B><I>back_insert_iterator</I></B> for a particular collection type.</P></LI>
|
|
<LI><P CLASS="LIST">The class <B><I><A HREF="front-insert-iterator.html">front_insert_iterator</A></I></B> is used to insert items at the start of a collection. The function <SAMP><A HREF="front-insert-iterator.html">front_inserter()</A></SAMP> creates an instance of a <B><I>front_insert_iterator</I></B> for a particular collection type. </P></LI>
|
|
<LI><P CLASS="LIST">An <B><I><A HREF="insert-iterator.html">insert_iterator</A></I></B> inserts new items into a collection at a location defined by an iterator supplied to the constructor. Like the other insert iterators, <B><I>insert_iterator</I></B> has a helper function called <SAMP><A HREF="insert-iterator.html">inserter()</A></SAMP>, which takes a collection and an iterator into that collection, and creates an instance of the <B><I>insert_iterator</I></B>. </P></LI>
|
|
</UL>
|
|
<A NAME="sec5"><H3>Interface</H3></A>
|
|
|
|
<UL><PRE>namespace std{
|
|
|
|
template <class Container>
|
|
class insert_iterator : public
|
|
iterator<output_iterator_tag,void,void,void,void>; {
|
|
|
|
public:
|
|
typedef Container container_type;
|
|
insert_iterator(Container&, typename
|
|
Container::iterator);
|
|
insert_iterator<Container>&
|
|
operator=(const typename Container::value_type&);
|
|
insert_iterator<Container>& operator*();
|
|
insert_iterator<Container>& operator++();
|
|
insert_iterator<Container>& operator++(int);
|
|
};
|
|
|
|
template <class Container>
|
|
class back_insert_iterator : public
|
|
iterator<output_iterator_tag,void,void,void,void> ; {
|
|
|
|
public:
|
|
typedef Container container_type;
|
|
explicit back_insert_iterator(Container&);
|
|
back_insert_iterator<Container>&
|
|
operator=(const typename Container::value_type&);
|
|
back_insert_iterator<Container>& operator*();
|
|
back_insert_iterator<Container>& operator++();
|
|
back_insert_iterator<Container> operator++(int);
|
|
};
|
|
|
|
template <class Container>
|
|
class front_insert_iterator : public
|
|
iterator<output_iterator_tag,void,void,void,void>;
|
|
{
|
|
|
|
public:
|
|
typedef Container container_type;
|
|
explicit front_insert_iterator(Container&);
|
|
front_insert_iterator<Container>&
|
|
operator=(const typename Container::value_type&);
|
|
front_insert_iterator<Container>& operator*();
|
|
front_insert_iterator<Container>& operator++();
|
|
front_insert_iterator<Container> operator++(int);
|
|
};
|
|
|
|
template <class Container, class Iterator>
|
|
insert_iterator<Container> inserter(Container&, Iterator);
|
|
|
|
template <class Container>
|
|
back_insert_iterator<Container> <SAMP><A HREF="back-insert-iterator.html">back_inserter</A></SAMP>(Container&);
|
|
|
|
template <class Container>
|
|
front_insert_iterator<Container>
|
|
<SAMP><A HREF="front-insert-iterator.html">front_inserter</A></SAMP>(Container&);
|
|
}
|
|
</PRE></UL>
|
|
<A NAME="sec6"><H3>See Also</H3></A>
|
|
<P><B><I><A HREF="back-insert-iterator.html">back_insert_iterator</A></I></B>, <B><I><A HREF="front-insert-iterator.html">front_insert_iterator</A></I></B>, <B><I><A HREF="insert-iterator.html">insert_iterator</A></I></B></P>
|
|
<A NAME="sec7"><H3>Standards Conformance</H3></A>
|
|
<P><I>ISO/IEC 14882:1998 -- International Standard for Information Systems -- Programming Language C++, Section 24.4.2</I></P>
|
|
|
|
<BR>
|
|
<HR>
|
|
<A HREF="inputiterators.html"><IMG SRC="images/bprev.gif" WIDTH=20 HEIGHT=21 ALT="Previous file" BORDER=O></A><A HREF="noframes.html"><IMG SRC="images/btop.gif" WIDTH=56 HEIGHT=21 ALT="Top of Document" BORDER=O></A><A HREF="booktoc.html"><IMG SRC="images/btoc.gif" WIDTH=56 HEIGHT=21 ALT="Contents" BORDER=O></A><A HREF="tindex.html"><IMG SRC="images/bindex.gif" WIDTH=56 HEIGHT=21 ALT="Index page" BORDER=O></A><A HREF="insert-iterator.html"><IMG SRC="images/bnext.gif" WIDTH=20 HEIGHT=21 ALT="Next file" BORDER=O></A>
|
|
|
|
<!-- Google Analytics tracking code -->
|
|
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
|
|
</script>
|
|
<script type="text/javascript">
|
|
_uacct = "UA-1775151-1";
|
|
urchinTracker();
|
|
</script>
|
|
<!-- end of Google Analytics tracking code -->
|
|
|
|
</BODY>
|
|
</HTML>
|