1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Class iterator_range</title> 5<link rel="stylesheet" href="../../../../../../../doc/src/boostbook.css" type="text/css"> 6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 7<link rel="home" href="../../../index.html" title="Chapter 1. Range 2.0"> 8<link rel="up" href="../utilities.html" title="Utilities"> 9<link rel="prev" href="../utilities.html" title="Utilities"> 10<link rel="next" href="sub_range.html" title="Class sub_range"> 11</head> 12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 13<table cellpadding="2" width="100%"><tr> 14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td> 15<td align="center"><a href="../../../../../../../index.html">Home</a></td> 16<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td> 17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> 18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> 19<td align="center"><a href="../../../../../../../more/index.htm">More</a></td> 20</tr></table> 21<hr> 22<div class="spirit-nav"> 23<a accesskey="p" href="../utilities.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../utilities.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="sub_range.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="section"> 26<div class="titlepage"><div><div><h4 class="title"> 27<a name="range.reference.utilities.iterator_range"></a><a class="link" href="iterator_range.html" title="Class iterator_range">Class <code class="computeroutput"><span class="identifier">iterator_range</span></code></a> 28</h4></div></div></div> 29<p> 30 The intention of the <code class="computeroutput"><span class="identifier">iterator_range</span></code> 31 class is to encapsulate two iterators so they fulfill the <a class="link" href="../../concepts/forward_range.html" title="Forward Range">Forward 32 Range</a> concept. A few other functions are also provided for convenience. 33 </p> 34<p> 35 If the template argument is not a model of <a href="../../../../../../../libs/iterator/doc/new-iter-concepts.html#forward-traversal-iterators-lib-forward-traversal-iterators" target="_top">Forward 36 Traversal Iterator</a>, one can still use a subset of the interface. 37 In particular, <code class="computeroutput"><span class="identifier">size</span><span class="special">()</span></code> 38 requires Random Access Traversal Iterators whereas <code class="computeroutput"><span class="identifier">empty</span><span class="special">()</span></code> only requires Single Pass Iterators. 39 </p> 40<p> 41 Recall that many default constructed iterators are <span class="bold"><strong><span class="emphasis"><em>singular</em></span></strong></span> 42 and hence can only be assigned, but not compared or incremented or anything. 43 However, if one creates a default constructed <code class="computeroutput"><span class="identifier">iterator_range</span></code>, 44 then one can still call all its member functions. This design decision 45 avoids the <code class="computeroutput"><span class="identifier">iterator_range</span></code> 46 imposing limitations upon ranges of iterators that are not singular. Any 47 singularity limitation is simply propagated from the underlying iterator 48 type. 49 </p> 50<h5> 51<a name="range.reference.utilities.iterator_range.h0"></a> 52 <span class="phrase"><a name="range.reference.utilities.iterator_range.synopsis"></a></span><a class="link" href="iterator_range.html#range.reference.utilities.iterator_range.synopsis">Synopsis</a> 53 </h5> 54<p> 55 The core functionality is in the header file <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">range</span><span class="special">/</span><span class="identifier">iterator_range_core</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code> 56 this includes all of the functionality except the <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">hash_value</span></code> 57 and <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">iostream</span></code> support. 58 </p> 59<p> 60 The <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">iostream</span></code> support is in the header <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">range</span><span class="special">/</span><span class="identifier">iterator_core</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code> while the <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">hash_value</span></code> 61 support is in <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">range</span><span class="special">/</span><span class="identifier">iterator_range_hash</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code> 62 </p> 63<p> 64</p> 65<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> 66<span class="special">{</span> 67 <span class="keyword">template</span><span class="special"><</span> <span class="keyword">class</span> <span class="identifier">ForwardTraversalIterator</span> <span class="special">></span> 68 <span class="keyword">class</span> <span class="identifier">iterator_range</span> 69 <span class="special">{</span> 70 <span class="keyword">public</span><span class="special">:</span> <span class="comment">// Forward Range types</span> 71 <span class="keyword">typedef</span> <span class="identifier">ForwardTraversalIterator</span> <span class="identifier">iterator</span><span class="special">;</span> 72 <span class="keyword">typedef</span> <span class="identifier">ForwardTraversalIterator</span> <span class="identifier">const_iterator</span><span class="special">;</span> 73 <span class="keyword">typedef</span> <span class="identifier">iterator_difference</span><span class="special"><</span><span class="identifier">iterator</span><span class="special">>::</span><span class="identifier">type</span> <span class="identifier">difference_type</span><span class="special">;</span> 74 75 <span class="keyword">public</span><span class="special">:</span> <span class="comment">// construction, assignment</span> 76 <span class="keyword">template</span><span class="special"><</span> <span class="keyword">class</span> <span class="identifier">ForwardTraversalIterator2</span> <span class="special">></span> 77 <span class="identifier">iterator_range</span><span class="special">(</span> <span class="identifier">ForwardTraversalIterator2</span> <span class="identifier">Begin</span><span class="special">,</span> <span class="identifier">ForwardTraversalIterator2</span> <span class="identifier">End</span> <span class="special">);</span> 78 79 <span class="keyword">template</span><span class="special"><</span> <span class="keyword">class</span> <span class="identifier">ForwardRange</span> <span class="special">></span> 80 <span class="identifier">iterator_range</span><span class="special">(</span> <span class="identifier">ForwardRange</span><span class="special">&</span> <span class="identifier">r</span> <span class="special">);</span> 81 82 <span class="keyword">template</span><span class="special"><</span> <span class="keyword">class</span> <span class="identifier">ForwardRange</span> <span class="special">></span> 83 <span class="identifier">iterator_range</span><span class="special">(</span> <span class="keyword">const</span> <span class="identifier">ForwardRange</span><span class="special">&</span> <span class="identifier">r</span> <span class="special">);</span> 84 85 <span class="keyword">template</span><span class="special"><</span> <span class="keyword">class</span> <span class="identifier">ForwardRange</span> <span class="special">></span> 86 <span class="identifier">iterator_range</span><span class="special">&</span> <span class="keyword">operator</span><span class="special">=(</span> <span class="identifier">ForwardRange</span><span class="special">&</span> <span class="identifier">r</span> <span class="special">);</span> 87 88 <span class="keyword">template</span><span class="special"><</span> <span class="keyword">class</span> <span class="identifier">ForwardRange</span> <span class="special">></span> 89 <span class="identifier">iterator_range</span><span class="special">&</span> <span class="keyword">operator</span><span class="special">=(</span> <span class="keyword">const</span> <span class="identifier">ForwardRange</span><span class="special">&</span> <span class="identifier">r</span> <span class="special">);</span> 90 91 <span class="keyword">public</span><span class="special">:</span> <span class="comment">// Forward Range functions</span> 92 <span class="identifier">iterator</span> <span class="identifier">begin</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span> 93 <span class="identifier">iterator</span> <span class="identifier">end</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span> 94 95 <span class="keyword">public</span><span class="special">:</span> <span class="comment">// convenience</span> 96 <span class="keyword">operator</span> <span class="identifier">unspecified_bool_type</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span> 97 <span class="keyword">bool</span> <span class="identifier">equal</span><span class="special">(</span> <span class="keyword">const</span> <span class="identifier">iterator_range</span><span class="special">&</span> <span class="special">)</span> <span class="keyword">const</span><span class="special">;</span> 98 <span class="identifier">value_type</span><span class="special">&</span> <span class="identifier">front</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span> 99 <span class="keyword">void</span> <span class="identifier">drop_front</span><span class="special">();</span> 100 <span class="keyword">void</span> <span class="identifier">drop_front</span><span class="special">(</span><span class="identifier">difference_type</span> <span class="identifier">n</span><span class="special">);</span> 101 <span class="keyword">bool</span> <span class="identifier">empty</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span> 102 103 <span class="identifier">iterator_range</span><span class="special">&</span> <span class="identifier">advance_begin</span><span class="special">(</span><span class="identifier">difference_type</span> <span class="identifier">n</span><span class="special">);</span> 104 <span class="identifier">iterator_range</span><span class="special">&</span> <span class="identifier">advance_end</span><span class="special">(</span><span class="identifier">difference_type</span> <span class="identifier">n</span><span class="special">);</span> 105 106 <span class="comment">// for Bidirectional:</span> 107 <span class="identifier">value_type</span><span class="special">&</span> <span class="identifier">back</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span> 108 <span class="keyword">void</span> <span class="identifier">drop_back</span><span class="special">();</span> 109 <span class="keyword">void</span> <span class="identifier">drop_back</span><span class="special">(</span><span class="identifier">difference_type</span> <span class="identifier">n</span><span class="special">);</span> 110 <span class="comment">// for Random Access only:</span> 111 <span class="identifier">reference</span> <span class="keyword">operator</span><span class="special">[](</span> <span class="identifier">difference_type</span> <span class="identifier">at</span> <span class="special">)</span> <span class="keyword">const</span><span class="special">;</span> 112 <span class="identifier">value_type</span> <span class="keyword">operator</span><span class="special">()(</span> <span class="identifier">difference_type</span> <span class="identifier">at</span> <span class="special">)</span> <span class="keyword">const</span><span class="special">;</span> 113 <span class="identifier">size_type</span> <span class="identifier">size</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span> 114 <span class="special">};</span> 115 116 <span class="comment">// stream output</span> 117 <span class="keyword">template</span><span class="special"><</span> <span class="keyword">class</span> <span class="identifier">ForwardTraversalIterator</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Traits</span> <span class="special">></span> 118 <span class="identifier">std</span><span class="special">::</span><span class="identifier">basic_ostream</span><span class="special"><</span><span class="identifier">T</span><span class="special">,</span><span class="identifier">Traits</span><span class="special">>&</span> 119 <span class="keyword">operator</span><span class="special"><<(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">basic_ostream</span><span class="special"><</span><span class="identifier">T</span><span class="special">,</span><span class="identifier">Traits</span><span class="special">>&</span> <span class="identifier">Os</span><span class="special">,</span> 120 <span class="keyword">const</span> <span class="identifier">iterator_range</span><span class="special"><</span><span class="identifier">ForwardTraversalIterator</span><span class="special">>&</span> <span class="identifier">r</span> <span class="special">);</span> 121 122 <span class="comment">// comparison</span> 123 <span class="keyword">template</span><span class="special"><</span> <span class="keyword">class</span> <span class="identifier">ForwardTraversalIterator</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">ForwardTraversalIterator2</span> <span class="special">></span> 124 <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">==(</span> <span class="keyword">const</span> <span class="identifier">iterator_range</span><span class="special"><</span><span class="identifier">ForwardTraversalIterator</span><span class="special">>&</span> <span class="identifier">l</span><span class="special">,</span> 125 <span class="keyword">const</span> <span class="identifier">iterator_range</span><span class="special"><</span><span class="identifier">ForwardTraversalIterator2</span><span class="special">>&</span> <span class="identifier">r</span> <span class="special">);</span> 126 127 <span class="keyword">template</span><span class="special"><</span> <span class="keyword">class</span> <span class="identifier">ForwardTraversalIterator</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">ForwardRange</span> <span class="special">></span> 128 <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">==(</span> <span class="keyword">const</span> <span class="identifier">iterator_range</span><span class="special"><</span><span class="identifier">ForwardTraversalIterator</span><span class="special">>&</span> <span class="identifier">l</span><span class="special">,</span> 129 <span class="keyword">const</span> <span class="identifier">ForwardRange</span><span class="special">&</span> <span class="identifier">r</span> <span class="special">);</span> 130 131 <span class="keyword">template</span><span class="special"><</span> <span class="keyword">class</span> <span class="identifier">ForwardTraversalIterator</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">ForwardRange</span> <span class="special">></span> 132 <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">==(</span> <span class="keyword">const</span> <span class="identifier">ForwardRange</span><span class="special">&</span> <span class="identifier">l</span><span class="special">,</span> 133 <span class="keyword">const</span> <span class="identifier">iterator_range</span><span class="special"><</span><span class="identifier">ForwardTraversalIterator</span><span class="special">>&</span> <span class="identifier">r</span> <span class="special">);</span> 134 135 <span class="keyword">template</span><span class="special"><</span> <span class="keyword">class</span> <span class="identifier">ForwardTraversalIterator</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">ForwardTraversalIterator2</span> <span class="special">></span> 136 <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">!=(</span> <span class="keyword">const</span> <span class="identifier">iterator_range</span><span class="special"><</span><span class="identifier">ForwardTraversalIterator</span><span class="special">>&</span> <span class="identifier">l</span><span class="special">,</span> 137 <span class="keyword">const</span> <span class="identifier">iterator_range</span><span class="special"><</span><span class="identifier">ForwardTraversalIterator2</span><span class="special">>&</span> <span class="identifier">r</span> <span class="special">);</span> 138 139 <span class="keyword">template</span><span class="special"><</span> <span class="keyword">class</span> <span class="identifier">ForwardTraversalIterator</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">ForwardRange</span> <span class="special">></span> 140 <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">!=(</span> <span class="keyword">const</span> <span class="identifier">iterator_range</span><span class="special"><</span><span class="identifier">ForwardTraversalIterator</span><span class="special">>&</span> <span class="identifier">l</span><span class="special">,</span> 141 <span class="keyword">const</span> <span class="identifier">ForwardRange</span><span class="special">&</span> <span class="identifier">r</span> <span class="special">);</span> 142 143 <span class="keyword">template</span><span class="special"><</span> <span class="keyword">class</span> <span class="identifier">ForwardTraversalIterator</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">ForwardRange</span> <span class="special">></span> 144 <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">!=(</span> <span class="keyword">const</span> <span class="identifier">ForwardRange</span><span class="special">&</span> <span class="identifier">l</span><span class="special">,</span> 145 <span class="keyword">const</span> <span class="identifier">iterator_range</span><span class="special"><</span><span class="identifier">ForwardTraversalIterator</span><span class="special">>&</span> <span class="identifier">r</span> <span class="special">);</span> 146 147 <span class="keyword">template</span><span class="special"><</span> <span class="keyword">class</span> <span class="identifier">ForwardTraversalIterator</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">ForwardTraversalIterator2</span> <span class="special">></span> 148 <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special"><(</span> <span class="keyword">const</span> <span class="identifier">iterator_range</span><span class="special"><</span><span class="identifier">ForwardTraversalIterator</span><span class="special">>&</span> <span class="identifier">l</span><span class="special">,</span> 149 <span class="keyword">const</span> <span class="identifier">iterator_range</span><span class="special"><</span><span class="identifier">ForwardTraversalIterator2</span><span class="special">>&</span> <span class="identifier">r</span> <span class="special">);</span> 150 151 <span class="keyword">template</span><span class="special"><</span> <span class="keyword">class</span> <span class="identifier">ForwardTraversalIterator</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">ForwardRange</span> <span class="special">></span> 152 <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special"><(</span> <span class="keyword">const</span> <span class="identifier">iterator_range</span><span class="special"><</span><span class="identifier">ForwardTraversalIterator</span><span class="special">>&</span> <span class="identifier">l</span><span class="special">,</span> 153 <span class="keyword">const</span> <span class="identifier">ForwardRange</span><span class="special">&</span> <span class="identifier">r</span> <span class="special">);</span> 154 155 <span class="keyword">template</span><span class="special"><</span> <span class="keyword">class</span> <span class="identifier">ForwardTraversalIterator</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">ForwardRange</span> <span class="special">></span> 156 <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special"><(</span> <span class="keyword">const</span> <span class="identifier">ForwardRange</span><span class="special">&</span> <span class="identifier">l</span><span class="special">,</span> 157 <span class="keyword">const</span> <span class="identifier">iterator_range</span><span class="special"><</span><span class="identifier">ForwardTraversalIterator</span><span class="special">>&</span> <span class="identifier">r</span> <span class="special">);</span> 158 159 <span class="comment">// external construction</span> 160 <span class="keyword">template</span><span class="special"><</span> <span class="keyword">class</span> <span class="identifier">ForwardTraversalIterator</span> <span class="special">></span> 161 <span class="identifier">iterator_range</span><span class="special"><</span> <span class="identifier">ForwardTraversalIterator</span> <span class="special">></span> 162 <span class="identifier">make_iterator_range</span><span class="special">(</span> <span class="identifier">ForwardTraversalIterator</span> <span class="identifier">Begin</span><span class="special">,</span> 163 <span class="identifier">ForwardTraversalIterator</span> <span class="identifier">End</span> <span class="special">);</span> 164 165 <span class="comment">// Make an iterator_range [first, boost::next(first, n) )</span> 166 <span class="keyword">template</span><span class="special"><</span> <span class="keyword">class</span> <span class="identifier">ForwardTraversalIterator</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Integer</span> <span class="special">></span> 167 <span class="identifier">iterator_range</span><span class="special"><</span> <span class="identifier">ForwardTraversalIterator</span> <span class="special">></span> 168 <span class="identifier">make_iterator_range_n</span><span class="special">(</span> <span class="identifier">ForwardTraversalIterator</span> <span class="identifier">first</span><span class="special">,</span> <span class="identifier">Integer</span> <span class="identifier">n</span> <span class="special">);</span> 169 170 171 <span class="keyword">template</span><span class="special"><</span> <span class="keyword">class</span> <span class="identifier">ForwardRange</span> <span class="special">></span> 172 <span class="identifier">iterator_range</span><span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">range_iterator</span><span class="special"><</span><span class="identifier">ForwardRange</span><span class="special">>::</span><span class="identifier">type</span> <span class="special">></span> 173 <span class="identifier">make_iterator_range</span><span class="special">(</span> <span class="identifier">ForwardRange</span><span class="special">&</span> <span class="identifier">r</span> <span class="special">);</span> 174 175 <span class="keyword">template</span><span class="special"><</span> <span class="keyword">class</span> <span class="identifier">ForwardRange</span> <span class="special">></span> 176 <span class="identifier">iterator_range</span><span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">range_iterator</span><span class="special"><</span><span class="keyword">const</span> <span class="identifier">ForwardRange</span><span class="special">>::</span><span class="identifier">type</span> <span class="special">></span> 177 <span class="identifier">make_iterator_range</span><span class="special">(</span> <span class="keyword">const</span> <span class="identifier">ForwardRange</span><span class="special">&</span> <span class="identifier">r</span> <span class="special">);</span> 178 179 <span class="keyword">template</span><span class="special"><</span> <span class="keyword">class</span> <span class="identifier">Range</span> <span class="special">></span> 180 <span class="identifier">iterator_range</span><span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">range_iterator</span><span class="special"><</span><span class="identifier">Range</span><span class="special">>::</span><span class="identifier">type</span> <span class="special">></span> 181 <span class="identifier">make_iterator_range</span><span class="special">(</span> <span class="identifier">Range</span><span class="special">&</span> <span class="identifier">r</span><span class="special">,</span> 182 <span class="keyword">typename</span> <span class="identifier">range_difference</span><span class="special"><</span><span class="identifier">Range</span><span class="special">>::</span><span class="identifier">type</span> <span class="identifier">advance_begin</span><span class="special">,</span> 183 <span class="keyword">typename</span> <span class="identifier">range_difference</span><span class="special"><</span><span class="identifier">Range</span><span class="special">>::</span><span class="identifier">type</span> <span class="identifier">advance_end</span> <span class="special">);</span> 184 185 <span class="keyword">template</span><span class="special"><</span> <span class="keyword">class</span> <span class="identifier">Range</span> <span class="special">></span> 186 <span class="identifier">iterator_range</span><span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">range_iterator</span><span class="special"><</span><span class="keyword">const</span> <span class="identifier">Range</span><span class="special">>::</span><span class="identifier">type</span> <span class="special">></span> 187 <span class="identifier">make_iterator_range</span><span class="special">(</span> <span class="keyword">const</span> <span class="identifier">Range</span><span class="special">&</span> <span class="identifier">r</span><span class="special">,</span> 188 <span class="keyword">typename</span> <span class="identifier">range_difference</span><span class="special"><</span><span class="keyword">const</span> <span class="identifier">Range</span><span class="special">>::</span><span class="identifier">type</span> <span class="identifier">advance_begin</span><span class="special">,</span> 189 <span class="keyword">typename</span> <span class="identifier">range_difference</span><span class="special"><</span><span class="keyword">const</span> <span class="identifier">Range</span><span class="special">>::</span><span class="identifier">type</span> <span class="identifier">advance_end</span> <span class="special">);</span> 190 191 <span class="comment">// convenience</span> 192 <span class="keyword">template</span><span class="special"><</span> <span class="keyword">class</span> <span class="identifier">Sequence</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">ForwardRange</span> <span class="special">></span> 193 <span class="identifier">Sequence</span> <span class="identifier">copy_range</span><span class="special">(</span> <span class="keyword">const</span> <span class="identifier">ForwardRange</span><span class="special">&</span> <span class="identifier">r</span> <span class="special">);</span> 194 195<span class="special">}</span> <span class="comment">// namespace 'boost'</span> 196</pre> 197<p> 198 </p> 199<p> 200 If an instance of <code class="computeroutput"><span class="identifier">iterator_range</span></code> 201 is constructed by a client with two iterators, the client must ensure that 202 the two iterators delimit a valid closed-open range [begin,end). 203 </p> 204<p> 205 It is worth noticing that the templated constructors and assignment operators 206 allow conversion from <code class="computeroutput"><span class="identifier">iterator_range</span><span class="special"><</span><span class="identifier">iterator</span><span class="special">></span></code> to <code class="computeroutput"><span class="identifier">iterator_range</span><span class="special"><</span><span class="identifier">const_iterator</span><span class="special">></span></code>. Similarly, since the comparison operators 207 have two template arguments, we can compare ranges whenever the iterators 208 are comparable; for example when we are dealing with const and non-const 209 iterators from the same container. 210 </p> 211<h5> 212<a name="range.reference.utilities.iterator_range.h1"></a> 213 <span class="phrase"><a name="range.reference.utilities.iterator_range.details_member_functions"></a></span><a class="link" href="iterator_range.html#range.reference.utilities.iterator_range.details_member_functions">Details 214 member functions</a> 215 </h5> 216<p> 217 <code class="computeroutput"><span class="keyword">operator</span> <span class="identifier">unspecified_bool_type</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span></code> 218 </p> 219<div class="blockquote"><blockquote class="blockquote"><p> 220 <span class="emphasis"><em><span class="bold"><strong>Returns</strong></span></em></span> <code class="computeroutput"><span class="special">!</span><span class="identifier">empty</span><span class="special">();</span></code> 221 </p></blockquote></div> 222<p> 223 <code class="computeroutput"><span class="keyword">bool</span> <span class="identifier">equal</span><span class="special">(</span> <span class="identifier">iterator_range</span><span class="special">&</span> <span class="identifier">r</span> <span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></code> 224 </p> 225<div class="blockquote"><blockquote class="blockquote"><p> 226 <span class="emphasis"><em><span class="bold"><strong>Returns</strong></span></em></span> <code class="computeroutput"><span class="identifier">begin</span><span class="special">()</span> <span class="special">==</span> <span class="identifier">r</span><span class="special">.</span><span class="identifier">begin</span><span class="special">()</span> <span class="special">&&</span> 227 <span class="identifier">end</span><span class="special">()</span> 228 <span class="special">==</span> <span class="identifier">r</span><span class="special">.</span><span class="identifier">end</span><span class="special">();</span></code> 229 </p></blockquote></div> 230<h5> 231<a name="range.reference.utilities.iterator_range.h2"></a> 232 <span class="phrase"><a name="range.reference.utilities.iterator_range.details_functions"></a></span><a class="link" href="iterator_range.html#range.reference.utilities.iterator_range.details_functions">Details 233 functions</a> 234 </h5> 235<p> 236 <code class="computeroutput"><span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">==(</span> <span class="keyword">const</span> <span class="identifier">ForwardRange1</span><span class="special">&</span> 237 <span class="identifier">l</span><span class="special">,</span> 238 <span class="keyword">const</span> <span class="identifier">ForwardRange2</span><span class="special">&</span> <span class="identifier">r</span> <span class="special">);</span></code> 239 </p> 240<div class="blockquote"><blockquote class="blockquote"><p> 241 <span class="emphasis"><em><span class="bold"><strong>Returns</strong></span></em></span> <code class="computeroutput"><span class="identifier">size</span><span class="special">(</span><span class="identifier">l</span><span class="special">)</span> <span class="special">!=</span> <span class="identifier">size</span><span class="special">(</span><span class="identifier">r</span><span class="special">)</span> <span class="special">?</span> <span class="keyword">false</span> 242 <span class="special">:</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">equal</span><span class="special">(</span> <span class="identifier">begin</span><span class="special">(</span><span class="identifier">l</span><span class="special">),</span> <span class="identifier">end</span><span class="special">(</span><span class="identifier">l</span><span class="special">),</span> <span class="identifier">begin</span><span class="special">(</span><span class="identifier">r</span><span class="special">)</span> <span class="special">);</span></code> 243 </p></blockquote></div> 244<p> 245 <code class="computeroutput"><span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">!=(</span> <span class="keyword">const</span> <span class="identifier">ForwardRange1</span><span class="special">&</span> 246 <span class="identifier">l</span><span class="special">,</span> 247 <span class="keyword">const</span> <span class="identifier">ForwardRange2</span><span class="special">&</span> <span class="identifier">r</span> <span class="special">);</span></code> 248 </p> 249<div class="blockquote"><blockquote class="blockquote"><p> 250 <span class="emphasis"><em><span class="bold"><strong>Returns</strong></span></em></span> <code class="computeroutput"><span class="special">!(</span> <span class="identifier">l</span> <span class="special">==</span> <span class="identifier">r</span> <span class="special">);</span></code> 251 </p></blockquote></div> 252<p> 253 <code class="computeroutput"><span class="keyword">bool</span> <span class="keyword">operator</span><span class="special"><(</span> <span class="keyword">const</span> <span class="identifier">ForwardRange1</span><span class="special">&</span> 254 <span class="identifier">l</span><span class="special">,</span> 255 <span class="keyword">const</span> <span class="identifier">ForwardRange2</span><span class="special">&</span> <span class="identifier">r</span> <span class="special">);</span></code> 256 </p> 257<div class="blockquote"><blockquote class="blockquote"><p> 258 <span class="emphasis"><em><span class="bold"><strong>Returns</strong></span></em></span> <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">lexicographical_compare</span><span class="special">(</span> 259 <span class="identifier">begin</span><span class="special">(</span><span class="identifier">l</span><span class="special">),</span> <span class="identifier">end</span><span class="special">(</span><span class="identifier">l</span><span class="special">),</span> <span class="identifier">begin</span><span class="special">(</span><span class="identifier">r</span><span class="special">),</span> <span class="identifier">end</span><span class="special">(</span><span class="identifier">r</span><span class="special">)</span> <span class="special">);</span></code> 260 </p></blockquote></div> 261<p> 262</p> 263<pre class="programlisting"><span class="identifier">iterator_range</span> <span class="identifier">make_iterator_range</span><span class="special">(</span> <span class="identifier">Range</span><span class="special">&</span> <span class="identifier">r</span><span class="special">,</span> 264 <span class="keyword">typename</span> <span class="identifier">range_difference</span><span class="special"><</span><span class="identifier">Range</span><span class="special">>::</span><span class="identifier">type</span> <span class="identifier">advance_begin</span><span class="special">,</span> 265 <span class="keyword">typename</span> <span class="identifier">range_difference</span><span class="special"><</span><span class="identifier">Range</span><span class="special">>::</span><span class="identifier">type</span> <span class="identifier">advance_end</span> <span class="special">);</span> 266</pre> 267<p> 268 </p> 269<div class="blockquote"><blockquote class="blockquote"><p> 270 <span class="emphasis"><em><span class="bold"><strong>Effects:</strong></span></em></span> 271 </p></blockquote></div> 272<p> 273</p> 274<pre class="programlisting"><span class="identifier">iterator</span> <span class="identifier">new_begin</span> <span class="special">=</span> <span class="identifier">begin</span><span class="special">(</span> <span class="identifier">r</span> <span class="special">),</span> 275<span class="identifier">iterator</span> <span class="identifier">new_end</span> <span class="special">=</span> <span class="identifier">end</span><span class="special">(</span> <span class="identifier">r</span> <span class="special">);</span> 276<span class="identifier">std</span><span class="special">::</span><span class="identifier">advance</span><span class="special">(</span> <span class="identifier">new_begin</span><span class="special">,</span> <span class="identifier">advance_begin</span> <span class="special">);</span> 277<span class="identifier">std</span><span class="special">::</span><span class="identifier">advance</span><span class="special">(</span> <span class="identifier">new_end</span><span class="special">,</span> <span class="identifier">advance_end</span> <span class="special">);</span> 278<span class="keyword">return</span> <span class="identifier">make_iterator_range</span><span class="special">(</span> <span class="identifier">new_begin</span><span class="special">,</span> <span class="identifier">new_end</span> <span class="special">);</span> 279</pre> 280<p> 281 </p> 282<p> 283 <code class="computeroutput"><span class="identifier">Sequence</span> <span class="identifier">copy_range</span><span class="special">(</span> <span class="keyword">const</span> <span class="identifier">ForwardRange</span><span class="special">&</span> 284 <span class="identifier">r</span> <span class="special">);</span></code> 285 </p> 286<div class="blockquote"><blockquote class="blockquote"><p> 287 <span class="emphasis"><em><span class="bold"><strong>Returns</strong></span></em></span> <code class="computeroutput"><span class="identifier">Sequence</span><span class="special">(</span> 288 <span class="identifier">begin</span><span class="special">(</span><span class="identifier">r</span><span class="special">),</span> <span class="identifier">end</span><span class="special">(</span><span class="identifier">r</span><span class="special">)</span> <span class="special">);</span></code> 289 </p></blockquote></div> 290</div> 291<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 292<td align="left"></td> 293<td align="right"><div class="copyright-footer">Copyright © 2003-2010 Thorsten Ottosen, 294 Neil Groves<p> 295 Distributed under the Boost Software License, Version 1.0. (See accompanying 296 file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>) 297 </p> 298</div></td> 299</tr></table> 300<hr> 301<div class="spirit-nav"> 302<a accesskey="p" href="../utilities.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../utilities.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="sub_range.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a> 303</div> 304</body> 305</html> 306