2004-01-27 04:12:54 +00:00
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
< html xmlns = "http://www.w3.org/1999/xhtml" xml:lang = "en" lang = "en" >
< head >
< meta http-equiv = "Content-Type" content = "text/html; charset=utf-8" / >
2006-09-11 22:27:29 +00:00
< meta name = "generator" content = "Docutils 0.4: http://docutils.sourceforge.net/" / >
2004-01-27 04:12:54 +00:00
< title > Zip Iterator< / title >
< meta name = "author" content = "David Abrahams, Thomas Becker" / >
< meta name = "organization" content = "Boost Consulting, Zephyr Associates, Inc." / >
2004-11-02 14:31:27 +00:00
< meta name = "date" content = "2004-11-01" / >
< meta name = "copyright" content = "Copyright David Abrahams and Thomas Becker 2003." / >
2006-09-11 22:27:29 +00:00
< style type = "text/css" >
/*
:Author: David Goodger
:Contact: goodger@users.sourceforge.net
:Date: $Date$
:Revision: $Revision$
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
customize this style sheet.
*/
/* used to remove borders from tables and images */
.borderless, table.borderless td, table.borderless th {
border: 0 }
table.borderless td, table.borderless th {
/* Override padding for "table.docutils td" with "! important".
The right padding separates the table cells. */
padding: 0 0.5em 0 0 ! important }
.first {
/* Override more specific margin styles with "! important". */
margin-top: 0 ! important }
.last, .with-subtitle {
margin-bottom: 0 ! important }
.hidden {
display: none }
a.toc-backref {
text-decoration: none ;
color: black }
blockquote.epigraph {
margin: 2em 5em ; }
dl.docutils dd {
margin-bottom: 0.5em }
/* Uncomment (and remove this text!) to get bold-faced definition list terms
dl.docutils dt {
font-weight: bold }
*/
div.abstract {
margin: 2em 5em }
div.abstract p.topic-title {
font-weight: bold ;
text-align: center }
div.admonition, div.attention, div.caution, div.danger, div.error,
div.hint, div.important, div.note, div.tip, div.warning {
margin: 2em ;
border: medium outset ;
padding: 1em }
div.admonition p.admonition-title, div.hint p.admonition-title,
div.important p.admonition-title, div.note p.admonition-title,
div.tip p.admonition-title {
font-weight: bold ;
font-family: sans-serif }
div.attention p.admonition-title, div.caution p.admonition-title,
div.danger p.admonition-title, div.error p.admonition-title,
div.warning p.admonition-title {
color: red ;
font-weight: bold ;
font-family: sans-serif }
/* Uncomment (and remove this text!) to get reduced vertical space in
compound paragraphs.
div.compound .compound-first, div.compound .compound-middle {
margin-bottom: 0.5em }
div.compound .compound-last, div.compound .compound-middle {
margin-top: 0.5em }
*/
div.dedication {
margin: 2em 5em ;
text-align: center ;
font-style: italic }
div.dedication p.topic-title {
font-weight: bold ;
font-style: normal }
div.figure {
margin-left: 2em ;
margin-right: 2em }
div.footer, div.header {
clear: both;
font-size: smaller }
div.line-block {
display: block ;
margin-top: 1em ;
margin-bottom: 1em }
div.line-block div.line-block {
margin-top: 0 ;
margin-bottom: 0 ;
margin-left: 1.5em }
div.sidebar {
margin-left: 1em ;
border: medium outset ;
padding: 1em ;
background-color: #ffffee ;
width: 40% ;
float: right ;
clear: right }
div.sidebar p.rubric {
font-family: sans-serif ;
font-size: medium }
div.system-messages {
margin: 5em }
div.system-messages h1 {
color: red }
div.system-message {
border: medium outset ;
padding: 1em }
div.system-message p.system-message-title {
color: red ;
font-weight: bold }
div.topic {
margin: 2em }
h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
margin-top: 0.4em }
h1.title {
text-align: center }
h2.subtitle {
text-align: center }
hr.docutils {
width: 75% }
img.align-left {
clear: left }
img.align-right {
clear: right }
ol.simple, ul.simple {
margin-bottom: 1em }
ol.arabic {
list-style: decimal }
ol.loweralpha {
list-style: lower-alpha }
ol.upperalpha {
list-style: upper-alpha }
ol.lowerroman {
list-style: lower-roman }
ol.upperroman {
list-style: upper-roman }
p.attribution {
text-align: right ;
margin-left: 50% }
p.caption {
font-style: italic }
p.credits {
font-style: italic ;
font-size: smaller }
p.label {
white-space: nowrap }
p.rubric {
font-weight: bold ;
font-size: larger ;
color: maroon ;
text-align: center }
p.sidebar-title {
font-family: sans-serif ;
font-weight: bold ;
font-size: larger }
p.sidebar-subtitle {
font-family: sans-serif ;
font-weight: bold }
p.topic-title {
font-weight: bold }
pre.address {
margin-bottom: 0 ;
margin-top: 0 ;
font-family: serif ;
font-size: 100% }
pre.literal-block, pre.doctest-block {
margin-left: 2em ;
margin-right: 2em ;
background-color: #eeeeee }
span.classifier {
font-family: sans-serif ;
font-style: oblique }
span.classifier-delimiter {
font-family: sans-serif ;
font-weight: bold }
span.interpreted {
font-family: sans-serif }
span.option {
white-space: nowrap }
span.pre {
white-space: pre }
span.problematic {
color: red }
span.section-subtitle {
/* font-size relative to parent (h1..h6 element) */
font-size: 80% }
table.citation {
border-left: solid 1px gray;
margin-left: 1px }
table.docinfo {
margin: 2em 4em }
table.docutils {
margin-top: 0.5em ;
margin-bottom: 0.5em }
table.footnote {
border-left: solid 1px black;
margin-left: 1px }
table.docutils td, table.docutils th,
table.docinfo td, table.docinfo th {
padding-left: 0.5em ;
padding-right: 0.5em ;
vertical-align: top }
table.docutils th.field-name, table.docinfo th.docinfo-name {
font-weight: bold ;
text-align: left ;
white-space: nowrap ;
padding-left: 0 }
h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
font-size: 100% }
tt.docutils {
background-color: #eeeeee }
ul.auto-toc {
list-style-type: none }
< / style >
2004-01-27 04:12:54 +00:00
< / head >
< body >
2005-05-20 15:32:55 +00:00
< div class = "document" id = "zip-iterator" >
2004-01-27 04:12:54 +00:00
< h1 class = "title" > Zip Iterator< / h1 >
< table class = "docinfo" frame = "void" rules = "none" >
< col class = "docinfo-name" / >
< col class = "docinfo-content" / >
< tbody valign = "top" >
< tr > < th class = "docinfo-name" > Author:< / th >
< td > David Abrahams, Thomas Becker< / td > < / tr >
< tr > < th class = "docinfo-name" > Contact:< / th >
< td > < a class = "first reference" href = "mailto:dave@boost-consulting.com" > dave@ boost-consulting.com< / a > , < a class = "last reference" href = "mailto:thomas@styleadvisor.com" > thomas@ styleadvisor.com< / a > < / td > < / tr >
< tr > < th class = "docinfo-name" > Organization:< / th >
< td > < a class = "first reference" href = "http://www.boost-consulting.com" > Boost Consulting< / a > , < a class = "last reference" href = "http://www.styleadvisor.com" > Zephyr Associates, Inc.< / a > < / td > < / tr >
< tr > < th class = "docinfo-name" > Date:< / th >
2004-11-02 14:31:27 +00:00
< td > 2004-11-01< / td > < / tr >
2004-01-27 04:12:54 +00:00
< tr > < th class = "docinfo-name" > Copyright:< / th >
2004-11-02 14:31:27 +00:00
< td > Copyright David Abrahams and Thomas Becker 2003.< / td > < / tr >
2004-01-27 04:12:54 +00:00
< / tbody >
< / table >
2006-09-11 22:27:29 +00:00
<!-- Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
2005-05-20 15:32:55 +00:00
< table class = "docutils field-list" frame = "void" rules = "none" >
2004-01-27 04:12:54 +00:00
< col class = "field-name" / >
< col class = "field-body" / >
< tbody valign = "top" >
2006-09-11 22:27:29 +00:00
< tr class = "field" > < th class = "field-name" > abstract:< / th > < td class = "field-body" > <!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
The zip iterator provides the ability to parallel-iterate
over several controlled sequences simultaneously. A zip
2004-01-27 04:12:54 +00:00
iterator is constructed from a tuple of iterators. Moving
the zip iterator moves all the iterators in parallel.
Dereferencing the zip iterator returns a tuple that contains
the results of dereferencing the individual iterators.< / td >
< / tr >
< / tbody >
< / table >
2006-09-11 22:27:29 +00:00
< div class = "contents topic" >
< p class = "topic-title first" > < a id = "table-of-contents" name = "table-of-contents" > Table of Contents< / a > < / p >
2004-01-27 04:12:54 +00:00
< ul class = "simple" >
2005-05-20 15:32:55 +00:00
< li > < a class = "reference" href = "#zip-iterator-synopsis" id = "id1" name = "id1" > < tt class = "docutils literal" > < span class = "pre" > zip_iterator< / span > < / tt > synopsis< / a > < / li >
< li > < a class = "reference" href = "#zip-iterator-requirements" id = "id2" name = "id2" > < tt class = "docutils literal" > < span class = "pre" > zip_iterator< / span > < / tt > requirements< / a > < / li >
< li > < a class = "reference" href = "#zip-iterator-models" id = "id3" name = "id3" > < tt class = "docutils literal" > < span class = "pre" > zip_iterator< / span > < / tt > models< / a > < / li >
< li > < a class = "reference" href = "#zip-iterator-operations" id = "id4" name = "id4" > < tt class = "docutils literal" > < span class = "pre" > zip_iterator< / span > < / tt > operations< / a > < / li >
2004-10-31 12:38:45 +00:00
< li > < a class = "reference" href = "#examples" id = "id5" name = "id5" > Examples< / a > < / li >
2004-01-27 04:12:54 +00:00
< / ul >
< / div >
2006-09-11 22:27:29 +00:00
< div class = "section" >
< h1 > < a class = "toc-backref" href = "#id1" id = "zip-iterator-synopsis" name = "zip-iterator-synopsis" > < tt class = "docutils literal" > < span class = "pre" > zip_iterator< / span > < / tt > synopsis< / a > < / h1 >
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
2004-01-27 04:12:54 +00:00
< pre class = "literal-block" >
template< typename IteratorTuple>
class zip_iterator
2006-09-11 22:27:29 +00:00
{
2004-01-27 04:12:54 +00:00
public:
typedef /* see below */ reference;
typedef reference value_type;
typedef value_type* pointer;
typedef /* see below */ difference_type;
typedef /* see below */ iterator_category;
zip_iterator();
zip_iterator(IteratorTuple iterator_tuple);
template< typename OtherIteratorTuple>
zip_iterator(
const zip_iterator< OtherIteratorTuple> & other
, typename enable_if_convertible<
OtherIteratorTuple
, IteratorTuple> ::type* = 0 // exposition only
);
const IteratorTuple& get_iterator_tuple() const;
private:
IteratorTuple m_iterator_tuple; // exposition only
};
2006-09-11 22:27:29 +00:00
template< typename IteratorTuple>
zip_iterator< IteratorTuple>
2004-01-27 04:12:54 +00:00
make_zip_iterator(IteratorTuple t);
< / pre >
2005-05-20 15:32:55 +00:00
< p > The < tt class = "docutils literal" > < span class = "pre" > reference< / span > < / tt > member of < tt class = "docutils literal" > < span class = "pre" > zip_iterator< / span > < / tt > is the type of the tuple
made of the reference types of the iterator types in the < tt class = "docutils literal" > < span class = "pre" > IteratorTuple< / span > < / tt >
2004-01-27 04:12:54 +00:00
argument.< / p >
2005-05-20 15:32:55 +00:00
< p > The < tt class = "docutils literal" > < span class = "pre" > difference_type< / span > < / tt > member of < tt class = "docutils literal" > < span class = "pre" > zip_iterator< / span > < / tt > is the < tt class = "docutils literal" > < span class = "pre" > difference_type< / span > < / tt >
of the first of the iterator types in the < tt class = "docutils literal" > < span class = "pre" > IteratorTuple< / span > < / tt > argument.< / p >
< p > The < tt class = "docutils literal" > < span class = "pre" > iterator_category< / span > < / tt > member of < tt class = "docutils literal" > < span class = "pre" > zip_iterator< / span > < / tt > is convertible to the
minimum of the traversal categories of the iterator types in the < tt class = "docutils literal" > < span class = "pre" > IteratorTuple< / span > < / tt >
argument. For example, if the < tt class = "docutils literal" > < span class = "pre" > zip_iterator< / span > < / tt > holds only vector
2006-09-11 22:27:29 +00:00
iterators, then < tt class = "docutils literal" > < span class = "pre" > iterator_category< / span > < / tt > is convertible to
2005-05-20 15:32:55 +00:00
< tt class = "docutils literal" > < span class = "pre" > boost::random_access_traversal_tag< / span > < / tt > . If you add a list iterator, then
< tt class = "docutils literal" > < span class = "pre" > iterator_category< / span > < / tt > will be convertible to < tt class = "docutils literal" > < span class = "pre" > boost::bidirectional_traversal_tag< / span > < / tt > ,
but no longer to < tt class = "docutils literal" > < span class = "pre" > boost::random_access_traversal_tag< / span > < / tt > .< / p >
2004-01-27 04:12:54 +00:00
< / div >
2006-09-11 22:27:29 +00:00
< div class = "section" >
< h1 > < a class = "toc-backref" href = "#id2" id = "zip-iterator-requirements" name = "zip-iterator-requirements" > < tt class = "docutils literal" > < span class = "pre" > zip_iterator< / span > < / tt > requirements< / a > < / h1 >
2005-05-20 15:32:55 +00:00
< p > All iterator types in the argument < tt class = "docutils literal" > < span class = "pre" > IteratorTuple< / span > < / tt > shall model Readable Iterator.< / p >
2004-01-27 04:12:54 +00:00
< / div >
2006-09-11 22:27:29 +00:00
< div class = "section" >
< h1 > < a class = "toc-backref" href = "#id3" id = "zip-iterator-models" name = "zip-iterator-models" > < tt class = "docutils literal" > < span class = "pre" > zip_iterator< / span > < / tt > models< / a > < / h1 >
2005-05-20 15:32:55 +00:00
< p > The resulting < tt class = "docutils literal" > < span class = "pre" > zip_iterator< / span > < / tt > models Readable Iterator.< / p >
2006-09-11 22:27:29 +00:00
< p > The fact that the < tt class = "docutils literal" > < span class = "pre" > zip_iterator< / span > < / tt > models only Readable Iterator does not
2004-01-27 04:12:54 +00:00
prevent you from modifying the values that the individual iterators point
2006-09-11 22:27:29 +00:00
to. The tuple returned by the < tt class = "docutils literal" > < span class = "pre" > zip_iterator< / span > < / tt > 's < tt class = "docutils literal" > < span class = "pre" > operator*< / span > < / tt > is a tuple
constructed from the reference types of the individual iterators, not
2005-05-20 15:32:55 +00:00
their value types. For example, if < tt class = "docutils literal" > < span class = "pre" > zip_it< / span > < / tt > is a < tt class = "docutils literal" > < span class = "pre" > zip_iterator< / span > < / tt > whose
first member iterator is an < tt class = "docutils literal" > < span class = "pre" > std::vector< double> ::iterator< / span > < / tt > , then the
2004-01-27 04:12:54 +00:00
following line will modify the value which the first member iterator of
2005-05-20 15:32:55 +00:00
< tt class = "docutils literal" > < span class = "pre" > zip_it< / span > < / tt > currently points to:< / p >
2004-01-27 04:12:54 +00:00
< pre class = "literal-block" >
zip_it-> get< 0> () = 42.0;
< / pre >
< p > Consider the set of standard traversal concepts obtained by taking
the most refined standard traversal concept modeled by each individual
2006-09-11 22:27:29 +00:00
iterator type in the < tt class = "docutils literal" > < span class = "pre" > IteratorTuple< / span > < / tt > argument.The < tt class = "docutils literal" > < span class = "pre" > zip_iterator< / span > < / tt >
2004-01-27 04:12:54 +00:00
models the least refined standard traversal concept in this set.< / p >
2005-05-20 15:32:55 +00:00
< p > < tt class = "docutils literal" > < span class = "pre" > zip_iterator< IteratorTuple1> < / span > < / tt > is interoperable with
< tt class = "docutils literal" > < span class = "pre" > zip_iterator< IteratorTuple2> < / span > < / tt > if and only if < tt class = "docutils literal" > < span class = "pre" > IteratorTuple1< / span > < / tt >
is interoperable with < tt class = "docutils literal" > < span class = "pre" > IteratorTuple2< / span > < / tt > .< / p >
2004-01-27 04:12:54 +00:00
< / div >
2006-09-11 22:27:29 +00:00
< div class = "section" >
< h1 > < a class = "toc-backref" href = "#id4" id = "zip-iterator-operations" name = "zip-iterator-operations" > < tt class = "docutils literal" > < span class = "pre" > zip_iterator< / span > < / tt > operations< / a > < / h1 >
2004-01-27 04:12:54 +00:00
< p > In addition to the operations required by the concepts modeled by
2005-05-20 15:32:55 +00:00
< tt class = "docutils literal" > < span class = "pre" > zip_iterator< / span > < / tt > , < tt class = "docutils literal" > < span class = "pre" > zip_iterator< / span > < / tt > provides the following
2004-01-27 04:12:54 +00:00
operations.< / p >
2005-05-20 15:32:55 +00:00
< p > < tt class = "docutils literal" > < span class = "pre" > zip_iterator();< / span > < / tt > < / p >
< table class = "docutils field-list" frame = "void" rules = "none" >
2004-01-27 04:12:54 +00:00
< col class = "field-name" / >
< col class = "field-body" / >
< tbody valign = "top" >
2005-05-20 15:32:55 +00:00
< tr class = "field" > < th class = "field-name" > Returns:< / th > < td class = "field-body" > An instance of < tt class = "docutils literal" > < span class = "pre" > zip_iterator< / span > < / tt > with < tt class = "docutils literal" > < span class = "pre" > m_iterator_tuple< / span > < / tt >
2004-01-27 04:12:54 +00:00
default constructed.< / td >
< / tr >
< / tbody >
< / table >
2005-05-20 15:32:55 +00:00
< p > < tt class = "docutils literal" > < span class = "pre" > zip_iterator(IteratorTuple< / span > < span class = "pre" > iterator_tuple);< / span > < / tt > < / p >
< table class = "docutils field-list" frame = "void" rules = "none" >
2004-01-27 04:12:54 +00:00
< col class = "field-name" / >
< col class = "field-body" / >
< tbody valign = "top" >
2005-05-20 15:32:55 +00:00
< tr class = "field" > < th class = "field-name" > Returns:< / th > < td class = "field-body" > An instance of < tt class = "docutils literal" > < span class = "pre" > zip_iterator< / span > < / tt > with < tt class = "docutils literal" > < span class = "pre" > m_iterator_tuple< / span > < / tt >
initialized to < tt class = "docutils literal" > < span class = "pre" > iterator_tuple< / span > < / tt > .< / td >
2004-01-27 04:12:54 +00:00
< / tr >
< / tbody >
< / table >
< pre class = "literal-block" >
template< typename OtherIteratorTuple>
zip_iterator(
const zip_iterator< OtherIteratorTuple> & other
, typename enable_if_convertible<
OtherIteratorTuple
, IteratorTuple> ::type* = 0 // exposition only
);
< / pre >
2005-05-20 15:32:55 +00:00
< table class = "docutils field-list" frame = "void" rules = "none" >
2004-01-27 04:12:54 +00:00
< col class = "field-name" / >
< col class = "field-body" / >
< tbody valign = "top" >
2005-05-20 15:32:55 +00:00
< tr class = "field" > < th class = "field-name" > Returns:< / th > < td class = "field-body" > An instance of < tt class = "docutils literal" > < span class = "pre" > zip_iterator< / span > < / tt > that is a copy of < tt class = "docutils literal" > < span class = "pre" > other< / span > < / tt > .< / td >
2004-01-27 04:12:54 +00:00
< / tr >
2005-05-20 15:32:55 +00:00
< tr class = "field" > < th class = "field-name" > Requires:< / th > < td class = "field-body" > < tt class = "docutils literal" > < span class = "pre" > OtherIteratorTuple< / span > < / tt > is implicitly convertible to < tt class = "docutils literal" > < span class = "pre" > IteratorTuple< / span > < / tt > .< / td >
2004-01-27 04:12:54 +00:00
< / tr >
< / tbody >
< / table >
2005-05-20 15:32:55 +00:00
< p > < tt class = "docutils literal" > < span class = "pre" > const< / span > < span class = "pre" > IteratorTuple& < / span > < span class = "pre" > get_iterator_tuple()< / span > < span class = "pre" > const;< / span > < / tt > < / p >
< table class = "docutils field-list" frame = "void" rules = "none" >
2004-01-27 04:12:54 +00:00
< col class = "field-name" / >
< col class = "field-body" / >
< tbody valign = "top" >
2005-05-20 15:32:55 +00:00
< tr class = "field" > < th class = "field-name" > Returns:< / th > < td class = "field-body" > < tt class = "docutils literal" > < span class = "pre" > m_iterator_tuple< / span > < / tt > < / td >
2004-01-27 04:12:54 +00:00
< / tr >
< / tbody >
< / table >
2005-05-20 15:32:55 +00:00
< p > < tt class = "docutils literal" > < span class = "pre" > reference< / span > < span class = "pre" > operator*()< / span > < span class = "pre" > const;< / span > < / tt > < / p >
< table class = "docutils field-list" frame = "void" rules = "none" >
2004-01-27 04:12:54 +00:00
< col class = "field-name" / >
< col class = "field-body" / >
< tbody valign = "top" >
< tr class = "field" > < th class = "field-name" > Returns:< / th > < td class = "field-body" > A tuple consisting of the results of dereferencing all iterators in
2005-05-20 15:32:55 +00:00
< tt class = "docutils literal" > < span class = "pre" > m_iterator_tuple< / span > < / tt > .< / td >
2004-01-27 04:12:54 +00:00
< / tr >
< / tbody >
< / table >
2005-05-20 15:32:55 +00:00
< p > < tt class = "docutils literal" > < span class = "pre" > zip_iterator& < / span > < span class = "pre" > operator++();< / span > < / tt > < / p >
< table class = "docutils field-list" frame = "void" rules = "none" >
2004-01-27 04:12:54 +00:00
< col class = "field-name" / >
< col class = "field-body" / >
< tbody valign = "top" >
2005-05-20 15:32:55 +00:00
< tr class = "field" > < th class = "field-name" > Effects:< / th > < td class = "field-body" > Increments each iterator in < tt class = "docutils literal" > < span class = "pre" > m_iterator_tuple< / span > < / tt > .< / td >
2004-01-27 04:12:54 +00:00
< / tr >
2005-05-20 15:32:55 +00:00
< tr class = "field" > < th class = "field-name" > Returns:< / th > < td class = "field-body" > < tt class = "docutils literal" > < span class = "pre" > *this< / span > < / tt > < / td >
2004-01-27 04:12:54 +00:00
< / tr >
< / tbody >
< / table >
2005-05-20 15:32:55 +00:00
< p > < tt class = "docutils literal" > < span class = "pre" > zip_iterator& < / span > < span class = "pre" > operator--();< / span > < / tt > < / p >
< table class = "docutils field-list" frame = "void" rules = "none" >
2004-01-27 04:12:54 +00:00
< col class = "field-name" / >
< col class = "field-body" / >
< tbody valign = "top" >
2005-05-20 15:32:55 +00:00
< tr class = "field" > < th class = "field-name" > Effects:< / th > < td class = "field-body" > Decrements each iterator in < tt class = "docutils literal" > < span class = "pre" > m_iterator_tuple< / span > < / tt > .< / td >
2004-01-27 04:12:54 +00:00
< / tr >
2005-05-20 15:32:55 +00:00
< tr class = "field" > < th class = "field-name" > Returns:< / th > < td class = "field-body" > < tt class = "docutils literal" > < span class = "pre" > *this< / span > < / tt > < / td >
2004-01-27 04:12:54 +00:00
< / tr >
< / tbody >
< / table >
< pre class = "literal-block" >
2006-09-11 22:27:29 +00:00
template< typename IteratorTuple>
zip_iterator< IteratorTuple>
2004-01-27 04:12:54 +00:00
make_zip_iterator(IteratorTuple t);
< / pre >
2005-05-20 15:32:55 +00:00
< table class = "docutils field-list" frame = "void" rules = "none" >
2004-01-27 04:12:54 +00:00
< col class = "field-name" / >
< col class = "field-body" / >
< tbody valign = "top" >
2005-05-20 15:32:55 +00:00
< tr class = "field" > < th class = "field-name" > Returns:< / th > < td class = "field-body" > An instance of < tt class = "docutils literal" > < span class = "pre" > zip_iterator< IteratorTuple> < / span > < / tt > with < tt class = "docutils literal" > < span class = "pre" > m_iterator_tuple< / span > < / tt >
initialized to < tt class = "docutils literal" > < span class = "pre" > t< / span > < / tt > .< / td >
2004-01-27 04:12:54 +00:00
< / tr >
< / tbody >
< / table >
2006-09-11 22:27:29 +00:00
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
2004-01-27 04:12:54 +00:00
< pre class = "literal-block" >
2006-09-11 22:27:29 +00:00
template< typename IteratorTuple>
zip_iterator< IteratorTuple>
2004-01-27 04:12:54 +00:00
make_zip_iterator(IteratorTuple t);
< / pre >
2005-05-20 15:32:55 +00:00
< table class = "docutils field-list" frame = "void" rules = "none" >
2004-01-27 04:12:54 +00:00
< col class = "field-name" / >
< col class = "field-body" / >
< tbody valign = "top" >
2005-05-20 15:32:55 +00:00
< tr class = "field" > < th class = "field-name" > Returns:< / th > < td class = "field-body" > An instance of < tt class = "docutils literal" > < span class = "pre" > zip_iterator< IteratorTuple> < / span > < / tt > with < tt class = "docutils literal" > < span class = "pre" > m_iterator_tuple< / span > < / tt >
initialized to < tt class = "docutils literal" > < span class = "pre" > t< / span > < / tt > .< / td >
2004-01-27 04:12:54 +00:00
< / tr >
< / tbody >
< / table >
2006-09-11 22:27:29 +00:00
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
<!-- Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
2004-01-27 04:12:54 +00:00
< / div >
2006-09-11 22:27:29 +00:00
< div class = "section" >
< h1 > < a class = "toc-backref" href = "#id5" id = "examples" name = "examples" > Examples< / a > < / h1 >
2005-05-20 15:32:55 +00:00
< p > There are two main types of applications of the < tt class = "docutils literal" > < span class = "pre" > zip_iterator< / span > < / tt > . The first
2004-01-27 04:12:54 +00:00
one concerns runtime efficiency: If one has several controlled sequences
2006-09-11 22:27:29 +00:00
of the same length that must be somehow processed, e.g., with the
2005-05-20 15:32:55 +00:00
< tt class = "docutils literal" > < span class = "pre" > for_each< / span > < / tt > algorithm, then it is more efficient to perform just
2006-09-11 22:27:29 +00:00
one parallel-iteration rather than several individual iterations. For an
2005-05-20 15:32:55 +00:00
example, assume that < tt class = "docutils literal" > < span class = "pre" > vect_of_doubles< / span > < / tt > and < tt class = "docutils literal" > < span class = "pre" > vect_of_ints< / span > < / tt >
2004-01-27 04:12:54 +00:00
are two vectors of equal length containing doubles and ints, respectively,
and consider the following two iterations:< / p >
< pre class = "literal-block" >
std::vector< double> ::const_iterator beg1 = vect_of_doubles.begin();
std::vector< double> ::const_iterator end1 = vect_of_doubles.end();
std::vector< int> ::const_iterator beg2 = vect_of_ints.begin();
std::vector< int> ::const_iterator end2 = vect_of_ints.end();
std::for_each(beg1, end1, func_0());
std::for_each(beg2, end2, func_1());
< / pre >
< p > These two iterations can now be replaced with a single one as follows:< / p >
< pre class = "literal-block" >
std::for_each(
boost::make_zip_iterator(
boost::make_tuple(beg1, beg2)
),
boost::make_zip_iterator(
boost::make_tuple(end1, end2)
),
zip_func()
);
< / pre >
2005-05-20 15:32:55 +00:00
< p > A non-generic implementation of < tt class = "docutils literal" > < span class = "pre" > zip_func< / span > < / tt > could look as follows:< / p >
2004-01-27 04:12:54 +00:00
< pre class = "literal-block" >
2006-09-11 22:27:29 +00:00
struct zip_func :
2004-01-27 04:12:54 +00:00
public std::unary_function< const boost::tuple< const double& , const int& > & , void>
{
void operator()(const boost::tuple< const double& , const int& > & t) const
{
m_f0(t.get< 0> ());
m_f1(t.get< 1> ());
}
private:
func_0 m_f0;
func_1 m_f1;
};
< / pre >
2005-05-20 15:32:55 +00:00
< p > The second important application of the < tt class = "docutils literal" > < span class = "pre" > zip_iterator< / span > < / tt > is as a building block
2004-01-27 04:12:54 +00:00
to make combining iterators. A combining iterator is an iterator
that parallel-iterates over several controlled sequences and, upon
dereferencing, returns the result of applying a functor to the values of the
sequences at the respective positions. This can now be achieved by using the
2005-05-20 15:32:55 +00:00
< tt class = "docutils literal" > < span class = "pre" > zip_iterator< / span > < / tt > in conjunction with the < tt class = "docutils literal" > < span class = "pre" > transform_iterator< / span > < / tt > .< / p >
2006-09-11 22:27:29 +00:00
< p > Suppose, for example, that you have two vectors of doubles, say
2005-05-20 15:32:55 +00:00
< tt class = "docutils literal" > < span class = "pre" > vect_1< / span > < / tt > and < tt class = "docutils literal" > < span class = "pre" > vect_2< / span > < / tt > , and you need to expose to a client
2006-09-11 22:27:29 +00:00
a controlled sequence containing the products of the elements of
2005-05-20 15:32:55 +00:00
< tt class = "docutils literal" > < span class = "pre" > vect_1< / span > < / tt > and < tt class = "docutils literal" > < span class = "pre" > vect_2< / span > < / tt > . Rather than placing these products
2004-01-27 04:12:54 +00:00
in a third vector, you can use a combining iterator that calculates the
2005-05-20 15:32:55 +00:00
products on the fly. Let us assume that < tt class = "docutils literal" > < span class = "pre" > tuple_multiplies< / span > < / tt > is a
functor that works like < tt class = "docutils literal" > < span class = "pre" > std::multiplies< / span > < / tt > , except that it takes
2006-09-11 22:27:29 +00:00
its two arguments packaged in a tuple. Then the two iterators
2005-05-20 15:32:55 +00:00
< tt class = "docutils literal" > < span class = "pre" > it_begin< / span > < / tt > and < tt class = "docutils literal" > < span class = "pre" > it_end< / span > < / tt > defined below delimit a controlled
sequence containing the products of the elements of < tt class = "docutils literal" > < span class = "pre" > vect_1< / span > < / tt > and
< tt class = "docutils literal" > < span class = "pre" > vect_2< / span > < / tt > :< / p >
2004-01-27 04:12:54 +00:00
< pre class = "literal-block" >
typedef boost::tuple<
std::vector< double> ::const_iterator,
std::vector< double> ::const_iterator
> the_iterator_tuple;
typedef boost::zip_iterator<
the_iterator_tuple
> the_zip_iterator;
typedef boost::transform_iterator<
tuple_multiplies< double> ,
the_zip_iterator
> the_transform_iterator;
the_transform_iterator it_begin(
the_zip_iterator(
the_iterator_tuple(
vect_1.begin(),
vect_2.begin()
)
),
tuple_multiplies< double> ()
);
the_transform_iterator it_end(
the_zip_iterator(
the_iterator_tuple(
vect_1.end(),
vect_2.end()
)
),
tuple_multiplies< double> ()
);
< / pre >
< / div >
< / div >
< / body >
< / html >