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.68.1"> |
---|
7 | <link rel="start" href="index.html" title="The Boost C++ Libraries BoostBook Documentation Subset"> |
---|
8 | <link rel="up" href="id620092-bb.html#concepts.reference" 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 C++ Libraries" 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="id620092-bb.html#concepts.reference"><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="id961649"></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="id961668"></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="id961690"></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<Iter>::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<Iter>::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<Iter>::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="id961747"></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="id961802"></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="id961821"></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 &</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> |
---|
118 | <code class="computeroutput">-n</code> times if <code class="computeroutput">n</code> is negative, and to a null |
---|
119 | operation if <code class="computeroutput">n</code> is zero.</p></td> |
---|
120 | </tr> |
---|
121 | <tr> |
---|
122 | <td><p>Motion (with integer offset)</p></td> |
---|
123 | <td><p>i += int_off</p></td> |
---|
124 | <td><p><span class="type">Iter &</span></p></td> |
---|
125 | <td><p>Equivalent to applying <code class="computeroutput">i++</code> <code class="computeroutput">n</code> times |
---|
126 | if <code class="computeroutput">n</code> is positive, applying <code class="computeroutput">i--</code> |
---|
127 | <code class="computeroutput">-n</code> times if <code class="computeroutput">n</code> is negative, and to a null |
---|
128 | operation if <code class="computeroutput">n</code> is zero.</p></td> |
---|
129 | </tr> |
---|
130 | <tr> |
---|
131 | <td><p>Subtractive motion</p></td> |
---|
132 | <td><p>i -= n</p></td> |
---|
133 | <td><p><span class="type">Iter &</span></p></td> |
---|
134 | <td><p>Equivalent to <code class="computeroutput">i+=(-n)</code></p></td> |
---|
135 | </tr> |
---|
136 | <tr> |
---|
137 | <td><p>Subtractive motion (with integer offset)</p></td> |
---|
138 | <td><p>i -= int_off</p></td> |
---|
139 | <td><p><span class="type">Iter &</span></p></td> |
---|
140 | <td><p>Equivalent to <code class="computeroutput">i+=(-n)</code></p></td> |
---|
141 | </tr> |
---|
142 | <tr> |
---|
143 | <td><p>Addition</p></td> |
---|
144 | <td><p>i + n</p></td> |
---|
145 | <td><p><span class="type">Iter</span></p></td> |
---|
146 | <td><p>Equivalent to <code class="computeroutput">{Iter j = i; j += n; return j;}</code></p></td> |
---|
147 | </tr> |
---|
148 | <tr> |
---|
149 | <td><p>Addition with integer</p></td> |
---|
150 | <td><p>i + int_off</p></td> |
---|
151 | <td><p><span class="type">Iter</span></p></td> |
---|
152 | <td><p>Equivalent to <code class="computeroutput">{Iter j = i; j += n; return j;}</code></p></td> |
---|
153 | </tr> |
---|
154 | <tr> |
---|
155 | <td><p>Addition (count first)</p></td> |
---|
156 | <td><p>n + i</p></td> |
---|
157 | <td><p><span class="type">Iter</span></p></td> |
---|
158 | <td><p>Equivalent to <code class="computeroutput">i + n</code></p></td> |
---|
159 | </tr> |
---|
160 | <tr> |
---|
161 | <td><p>Addition with integer (count first)</p></td> |
---|
162 | <td><p>int_off + i</p></td> |
---|
163 | <td><p><span class="type">Iter</span></p></td> |
---|
164 | <td><p>Equivalent to <code class="computeroutput">i + n</code></p></td> |
---|
165 | </tr> |
---|
166 | <tr> |
---|
167 | <td><p>Subtraction</p></td> |
---|
168 | <td><p>i - n</p></td> |
---|
169 | <td><p><span class="type">Iter</span></p></td> |
---|
170 | <td><p>Equivalent to <code class="computeroutput">i + (-n)</code></p></td> |
---|
171 | </tr> |
---|
172 | <tr> |
---|
173 | <td><p>Subtraction with integer</p></td> |
---|
174 | <td><p>i - int_off</p></td> |
---|
175 | <td><p><span class="type">Iter</span></p></td> |
---|
176 | <td><p>Equivalent to <code class="computeroutput">i + (-n)</code></p></td> |
---|
177 | </tr> |
---|
178 | <tr> |
---|
179 | <td><p>Distance</p></td> |
---|
180 | <td><p>i - j</p></td> |
---|
181 | <td><p><span class="type">difference_type</span></p></td> |
---|
182 | <td><p>The number of times <code class="computeroutput">i</code> must be incremented (or |
---|
183 | decremented if the result is negative) to reach <code class="computeroutput">j</code>. Not |
---|
184 | defined if <code class="computeroutput">j</code> is not reachable from |
---|
185 | <code class="computeroutput">i</code>.</p></td> |
---|
186 | </tr> |
---|
187 | <tr> |
---|
188 | <td><p>Element access</p></td> |
---|
189 | <td><p>i[n]</p></td> |
---|
190 | <td><p><span class="type">const-if-not-mutable value_type &</span></p></td> |
---|
191 | <td><p>Equivalent to <code class="computeroutput">*(i + n)</code></p></td> |
---|
192 | </tr> |
---|
193 | <tr> |
---|
194 | <td><p>Element access with integer index</p></td> |
---|
195 | <td><p>i[int_off]</p></td> |
---|
196 | <td><p><span class="type">const-if-not-mutable value_type &</span></p></td> |
---|
197 | <td><p>Equivalent to <code class="computeroutput">*(i + n)</code></p></td> |
---|
198 | </tr> |
---|
199 | </tbody> |
---|
200 | </table></div> |
---|
201 | </div> |
---|
202 | <div class="refsect1" lang="en"> |
---|
203 | <a name="id962204"></a><h2>Complexity</h2> |
---|
204 | <p> |
---|
205 | All iterator operations must take amortized constant time. |
---|
206 | </p> |
---|
207 | </div> |
---|
208 | <div class="refsect1" lang="en"> |
---|
209 | <a name="id962211"></a><h2>Models</h2> |
---|
210 | <div class="itemizedlist"><ul type="disc"> |
---|
211 | <li><span class="simplelist"><span class="type">T *</span></span></li> |
---|
212 | <li><span class="simplelist"><span class="type">std::vector<T>::iterator</span></span></li> |
---|
213 | <li><span class="simplelist"><span class="type">std::vector<T>::const_iterator</span></span></li> |
---|
214 | <li><span class="simplelist"><span class="type">std::deque<T>::iterator</span></span></li> |
---|
215 | <li><span class="simplelist"><span class="type">std::deque<T>::const_iterator</span></span></li> |
---|
216 | </ul></div> |
---|
217 | </div> |
---|
218 | <div class="refsect1" lang="en"> |
---|
219 | <a name="id962258"></a><h2>See also</h2> |
---|
220 | <div class="itemizedlist"><ul type="disc"><li><p><a href="LessThanComparable.html" title="Concept LessThanComparable">LessThanComparable</a></p></li></ul></div> |
---|
221 | </div> |
---|
222 | </div> |
---|
223 | <table width="100%"><tr> |
---|
224 | <td align="left"></td> |
---|
225 | <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> |
---|
226 | </tr></table> |
---|
227 | <hr> |
---|
228 | <div class="spirit-nav"> |
---|
229 | <a accesskey="p" href="BidirectionalIterator.html"><img src="images/prev.png" alt="Prev"></a><a accesskey="u" href="id620092-bb.html#concepts.reference"><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> |
---|
230 | </div> |
---|
231 | </body> |
---|
232 | </html> |
---|