Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/doc/html/RandomAccessIterator.html @ 25

Last change on this file since 25 was 12, checked in by landauf, 17 years ago

added boost

File size: 10.1 KB
RevLine 
[12]1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
4<title>Concept RandomAccessIterator</title>
5<link rel="stylesheet" href="boostbook.css" type="text/css">
6<meta name="generator" content="DocBook XSL Stylesheets V1.69.1">
7<link rel="start" href="index.html" title="The Boost C++ Libraries">
8<link rel="up" href="concepts/reference.html" title="Concept reference">
9<link rel="prev" href="BidirectionalIterator.html" title="Concept BidirectionalIterator">
10<link rel="next" href="DefaultConstructible.html" title="Concept DefaultConstructible">
11</head>
12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13<table cellpadding="2" width="100%">
14<td valign="top"><img alt="boost.png (6897 bytes)" width="277" height="86" src="../../boost.png"></td>
15<td align="center"><a href="../../index.htm">Home</a></td>
16<td align="center"><a href="../../libs/libraries.htm">Libraries</a></td>
17<td align="center"><a href="../../people/people.htm">People</a></td>
18<td align="center"><a href="../../more/faq.htm">FAQ</a></td>
19<td align="center"><a href="../../more/index.htm">More</a></td>
20</table>
21<hr>
22<div class="spirit-nav">
23<a accesskey="p" href="BidirectionalIterator.html"><img src="images/prev.png" alt="Prev"></a><a accesskey="u" href="concepts/reference.html"><img src="images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="images/home.png" alt="Home"></a><a accesskey="n" href="DefaultConstructible.html"><img src="images/next.png" alt="Next"></a>
24</div>
25<div class="refentry" lang="en">
26<a name="RandomAccessIterator"></a><div class="titlepage"></div>
27<div class="refnamediv">
28<h2><span class="refentrytitle">Concept RandomAccessIterator</span></h2>
29<p>RandomAccessIterator</p>
30</div>
31<div class="refsect1" lang="en">
32<a name="id2577701"></a><h2>Description</h2>
33<p>A random access iterator is an iterator that can read through
34  a sequence of values.  It can move in either direction through the
35  sequence (by any amount in constant time), and can be either mutable
36  (data pointed to by it can be changed) or not mutable.</p>
37<p>An iterator represents a position in a sequence.  Therefore,
38  the iterator can point into the sequence (returning a value when
39  dereferenced and being incrementable), or be off-the-end (and not
40  dereferenceable or incrementable).</p>
41</div>
42<div class="refsect1" lang="en">
43<a name="id2577717"></a><h2>Refinement of</h2>
44<div class="itemizedlist"><ul type="disc">
45<li><p><a href="BidirectionalIterator.html" title="Concept BidirectionalIterator">BidirectionalIterator</a></p></li>
46<li><p><a href="LessThanComparable.html" title="Concept LessThanComparable">LessThanComparable</a></p></li>
47</ul></div>
48</div>
49<div class="refsect1" lang="en">
50<a name="id2577739"></a><h2>Associated types</h2>
51<div class="itemizedlist"><ul type="disc">
52<li>
53<p><span class="bold"><strong>value_type</strong></span></p>
54<pre class="literallayout">std::iterator_traits&lt;Iter&gt;::value_type</pre>
55<p>The value type of the iterator</p>
56</li>
57<li>
58<p><span class="bold"><strong>category</strong></span></p>
59<pre class="literallayout">std::iterator_traits&lt;Iter&gt;::iterator_category</pre>
60<p>The category of the iterator</p>
61</li>
62<li>
63<p><span class="bold"><strong>difference_type</strong></span></p>
64<pre class="literallayout">std::iterator_traits&lt;Iter&gt;::difference_type</pre>
65<p>The difference type of the iterator (measure of the number
66    of steps between two iterators)</p>
67</li>
68</ul></div>
69</div>
70<div class="refsect1" lang="en">
71<a name="id2577798"></a><h2>Notation</h2>
72<div class="variablelist"><dl>
73<dt><span class="term">Iter</span></dt>
74<dd>A type playing the role of iterator-type in the <a href="RandomAccessIterator.html" title="Concept RandomAccessIterator">RandomAccessIterator</a> concept.</dd>
75<dt>
76<span class="term"><code class="varname">i</code>, </span><span class="term"><code class="varname">j</code></span>
77</dt>
78<dd>Objects of type Iter</dd>
79<dt><span class="term"><code class="varname">x</code></span></dt>
80<dd>Object of type value_type</dd>
81<dt><span class="term"><code class="varname">n</code></span></dt>
82<dd>Object of type difference_type</dd>
83<dt><span class="term"><code class="varname">int_off</code></span></dt>
84<dd>Object of type int</dd>
85</dl></div>
86</div>
87<div class="refsect1" lang="en">
88<a name="id2577853"></a><h2>Type expressions</h2>
89<div class="variablelist"><dl>
90<dt><span class="term">Category tag</span></dt>
91<dd><p><span class="type">category</span> must be
92                  derived from <span class="type">std::random_access_iterator_tag</span>.
93                </p></dd>
94</dl></div>
95</div>
96<div class="refsect1" lang="en">
97<a name="id2577872"></a><h2>Valid expressions</h2>
98<div class="informaltable"><table class="table">
99<colgroup>
100<col>
101<col>
102<col>
103<col>
104</colgroup>
105<thead><tr>
106<th>Name</th>
107<th>Expression</th>
108<th>Type</th>
109<th>Semantics</th>
110</tr></thead>
111<tbody>
112<tr>
113<td><p>Motion</p></td>
114<td><p>i += n</p></td>
115<td><p><span class="type">Iter &amp;</span></p></td>
116<td><p>Equivalent to applying <code class="computeroutput">i++</code><code class="computeroutput">n</code> times
117    if <code class="computeroutput">n</code> is positive, applying <code class="computeroutput">i--</code><code class="computeroutput">-n</code> times if <code class="computeroutput">n</code> is negative, and to a null
118    operation if <code class="computeroutput">n</code> is zero.</p></td>
119</tr>
120<tr>
121<td><p>Motion (with integer offset)</p></td>
122<td><p>i += int_off</p></td>
123<td><p><span class="type">Iter &amp;</span></p></td>
124<td><p>Equivalent to applying <code class="computeroutput">i++</code><code class="computeroutput">n</code> times
125    if <code class="computeroutput">n</code> is positive, applying <code class="computeroutput">i--</code><code class="computeroutput">-n</code> times if <code class="computeroutput">n</code> is negative, and to a null
126    operation if <code class="computeroutput">n</code> is zero.</p></td>
127</tr>
128<tr>
129<td><p>Subtractive motion</p></td>
130<td><p>i -= n</p></td>
131<td><p><span class="type">Iter &amp;</span></p></td>
132<td><p>Equivalent to <code class="computeroutput">i+=(-n)</code></p></td>
133</tr>
134<tr>
135<td><p>Subtractive motion (with integer offset)</p></td>
136<td><p>i -= int_off</p></td>
137<td><p><span class="type">Iter &amp;</span></p></td>
138<td><p>Equivalent to <code class="computeroutput">i+=(-n)</code></p></td>
139</tr>
140<tr>
141<td><p>Addition</p></td>
142<td><p>i + n</p></td>
143<td><p><span class="type">Iter</span></p></td>
144<td><p>Equivalent to <code class="computeroutput">{Iter j = i; j += n; return j;}</code></p></td>
145</tr>
146<tr>
147<td><p>Addition with integer</p></td>
148<td><p>i + int_off</p></td>
149<td><p><span class="type">Iter</span></p></td>
150<td><p>Equivalent to <code class="computeroutput">{Iter j = i; j += n; return j;}</code></p></td>
151</tr>
152<tr>
153<td><p>Addition (count first)</p></td>
154<td><p>n + i</p></td>
155<td><p><span class="type">Iter</span></p></td>
156<td><p>Equivalent to <code class="computeroutput">i + n</code></p></td>
157</tr>
158<tr>
159<td><p>Addition with integer (count first)</p></td>
160<td><p>int_off + i</p></td>
161<td><p><span class="type">Iter</span></p></td>
162<td><p>Equivalent to <code class="computeroutput">i + n</code></p></td>
163</tr>
164<tr>
165<td><p>Subtraction</p></td>
166<td><p>i - n</p></td>
167<td><p><span class="type">Iter</span></p></td>
168<td><p>Equivalent to <code class="computeroutput">i + (-n)</code></p></td>
169</tr>
170<tr>
171<td><p>Subtraction with integer</p></td>
172<td><p>i - int_off</p></td>
173<td><p><span class="type">Iter</span></p></td>
174<td><p>Equivalent to <code class="computeroutput">i + (-n)</code></p></td>
175</tr>
176<tr>
177<td><p>Distance</p></td>
178<td><p>i - j</p></td>
179<td><p><span class="type">difference_type</span></p></td>
180<td><p>The number of times <code class="computeroutput">i</code> must be incremented (or
181    decremented if the result is negative) to reach <code class="computeroutput">j</code>.  Not
182    defined if <code class="computeroutput">j</code> is not reachable from
183    <code class="computeroutput">i</code>.</p></td>
184</tr>
185<tr>
186<td><p>Element access</p></td>
187<td><p>i[n]</p></td>
188<td><p><span class="type">const-if-not-mutable value_type &amp;</span></p></td>
189<td><p>Equivalent to <code class="computeroutput">*(i + n)</code></p></td>
190</tr>
191<tr>
192<td><p>Element access with integer index</p></td>
193<td><p>i[int_off]</p></td>
194<td><p><span class="type">const-if-not-mutable value_type &amp;</span></p></td>
195<td><p>Equivalent to <code class="computeroutput">*(i + n)</code></p></td>
196</tr>
197</tbody>
198</table></div>
199</div>
200<div class="refsect1" lang="en">
201<a name="id2578257"></a><h2>Complexity</h2>
202<p>
203  All iterator operations must take amortized constant time.
204  </p>
205</div>
206<div class="refsect1" lang="en">
207<a name="id2578264"></a><h2>Models</h2>
208<div class="itemizedlist"><ul type="disc">
209<li><span class="simplelist"><span class="type">T *</span></span></li>
210<li><span class="simplelist"><span class="type">std::vector&lt;T&gt;::iterator</span></span></li>
211<li><span class="simplelist"><span class="type">std::vector&lt;T&gt;::const_iterator</span></span></li>
212<li><span class="simplelist"><span class="type">std::deque&lt;T&gt;::iterator</span></span></li>
213<li><span class="simplelist"><span class="type">std::deque&lt;T&gt;::const_iterator</span></span></li>
214</ul></div>
215</div>
216<div class="refsect1" lang="en">
217<a name="id2578310"></a><h2>See also</h2>
218<div class="itemizedlist"><ul type="disc"><li><p><a href="LessThanComparable.html" title="Concept LessThanComparable">LessThanComparable</a></p></li></ul></div>
219</div>
220</div>
221<table width="100%"><tr>
222<td align="left"></td>
223<td align="right"><small>Copyright © 2001, 2002 Indiana University<br>Copyright © 2000, 2001 University of Notre Dame du Lac<br>Copyright © 2000 Jeremy Siek, Lie-Quan Lee, Andrew Lumsdaine<br>Copyright © 1996-1999 Silicon Graphics Computer Systems, Inc.<br>Copyright © 1994 Hewlett-Packard Company</small></td>
224</tr></table>
225<hr>
226<div class="spirit-nav">
227<a accesskey="p" href="BidirectionalIterator.html"><img src="images/prev.png" alt="Prev"></a><a accesskey="u" href="concepts/reference.html"><img src="images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="images/home.png" alt="Home"></a><a accesskey="n" href="DefaultConstructible.html"><img src="images/next.png" alt="Next"></a>
228</div>
229</body>
230</html>
Note: See TracBrowser for help on using the repository browser.