Imported Upstream version 1.64.0
[platform/upstream/boost.git] / doc / html / RandomAccessIterator.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
5 <title>Concept RandomAccessIterator</title>
6 <link rel="stylesheet" href="../../doc/src/boostbook.css" type="text/css">
7 <meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
8 <link rel="home" href="index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
9 <link rel="up" href="idp14900640-bb.html#concepts.reference" title="Concept reference">
10 <link rel="prev" href="BidirectionalIterator.html" title="Concept BidirectionalIterator">
11 <link rel="next" href="DefaultConstructible.html" title="Concept DefaultConstructible">
12 </head>
13 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
14 <table cellpadding="2" width="100%"><tr>
15 <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../boost.png"></td>
16 <td align="center"><a href="../../index.html">Home</a></td>
17 <td align="center"><a href="../../libs/libraries.htm">Libraries</a></td>
18 <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
19 <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
20 <td align="center"><a href="../../more/index.htm">More</a></td>
21 </tr></table>
22 <hr>
23 <div class="spirit-nav">
24 <a accesskey="p" href="BidirectionalIterator.html"><img src="../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="idp14900640-bb.html#concepts.reference"><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="DefaultConstructible.html"><img src="../../doc/src/images/next.png" alt="Next"></a>
25 </div>
26 <div class="refentry">
27 <a name="RandomAccessIterator"></a><div class="titlepage"></div>
28 <div class="refnamediv">
29 <h2><span class="refentrytitle">Concept RandomAccessIterator</span></h2>
30 <p>RandomAccessIterator</p>
31 </div>
32 <div class="refsect1">
33 <a name="idp634456688"></a><h2>Description</h2>
34 <p>A random access iterator is an iterator that can read through
35   a sequence of values.  It can move in either direction through the
36   sequence (by any amount in constant time), and can be either mutable
37   (data pointed to by it can be changed) or not mutable.</p>
38 <p>An iterator represents a position in a sequence.  Therefore,
39   the iterator can point into the sequence (returning a value when
40   dereferenced and being incrementable), or be off-the-end (and not
41   dereferenceable or incrementable).</p>
42 </div>
43 <div class="refsect1">
44 <a name="idp634458528"></a><h2>Refinement of</h2>
45 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
46 <li class="listitem"><p><a class="link" href="BidirectionalIterator.html" title="Concept BidirectionalIterator">BidirectionalIterator</a></p></li>
47 <li class="listitem"><p><a class="link" href="LessThanComparable.html" title="Concept LessThanComparable">LessThanComparable</a></p></li>
48 </ul></div>
49 </div>
50 <div class="refsect1">
51 <a name="idp634460928"></a><h2>Associated types</h2>
52 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
53 <li class="listitem">
54 <p><span class="bold"><strong>value_type</strong></span></p>
55 <pre class="literallayout">std::iterator_traits&lt;Iter&gt;::value_type</pre>
56 <p>The value type of the iterator</p>
57 </li>
58 <li class="listitem">
59 <p><span class="bold"><strong>category</strong></span></p>
60 <pre class="literallayout">std::iterator_traits&lt;Iter&gt;::iterator_category</pre>
61 <p>The category of the iterator</p>
62 </li>
63 <li class="listitem">
64 <p><span class="bold"><strong>difference_type</strong></span></p>
65 <pre class="literallayout">std::iterator_traits&lt;Iter&gt;::difference_type</pre>
66 <p>The difference type of the iterator (measure of the number
67     of steps between two iterators)</p>
68 </li>
69 </ul></div>
70 </div>
71 <div class="refsect1">
72 <a name="idp634467568"></a><h2>Notation</h2>
73 <div class="variablelist"><dl class="variablelist">
74 <dt><span class="term">Iter</span></dt>
75 <dd>A type playing the role of iterator-type in the <a class="link" href="RandomAccessIterator.html" title="Concept RandomAccessIterator">RandomAccessIterator</a> concept.</dd>
76 <dt>
77 <span class="term"><code class="varname">i</code>, </span><span class="term"><code class="varname">j</code></span>
78 </dt>
79 <dd>Objects of type Iter</dd>
80 <dt><span class="term"><code class="varname">x</code></span></dt>
81 <dd>Object of type value_type</dd>
82 <dt><span class="term"><code class="varname">n</code></span></dt>
83 <dd>Object of type difference_type</dd>
84 <dt><span class="term"><code class="varname">int_off</code></span></dt>
85 <dd>Object of type int</dd>
86 </dl></div>
87 </div>
88 <div class="refsect1">
89 <a name="idp634473968"></a><h2>Type expressions</h2>
90 <div class="variablelist"><dl class="variablelist">
91 <dt><span class="term">Category tag</span></dt>
92 <dd><p><span class="type">category</span> must be
93                   derived from <span class="type">std::random_access_iterator_tag</span>.
94                 </p></dd>
95 </dl></div>
96 </div>
97 <div class="refsect1">
98 <a name="idp634476128"></a><h2>Valid expressions</h2>
99 <div class="informaltable"><table class="table">
100 <colgroup>
101 <col>
102 <col>
103 <col>
104 <col>
105 </colgroup>
106 <thead><tr>
107 <th>Name</th>
108 <th>Expression</th>
109 <th>Type</th>
110 <th>Semantics</th>
111 </tr></thead>
112 <tbody>
113 <tr>
114 <td><p>Motion</p></td>
115 <td><p>i += n</p></td>
116 <td><p><span class="type">Iter &amp;</span></p></td>
117 <td><p>Equivalent to applying <code class="computeroutput">i++</code> <code class="computeroutput">n</code> times
118     if <code class="computeroutput">n</code> is positive, applying <code class="computeroutput">i--</code>
119     <code class="computeroutput">-n</code> times if <code class="computeroutput">n</code> is negative, and to a null
120     operation if <code class="computeroutput">n</code> is zero.</p></td>
121 </tr>
122 <tr>
123 <td><p>Motion (with integer offset)</p></td>
124 <td><p>i += int_off</p></td>
125 <td><p><span class="type">Iter &amp;</span></p></td>
126 <td><p>Equivalent to applying <code class="computeroutput">i++</code> <code class="computeroutput">n</code> times
127     if <code class="computeroutput">n</code> is positive, applying <code class="computeroutput">i--</code>
128     <code class="computeroutput">-n</code> times if <code class="computeroutput">n</code> is negative, and to a null
129     operation if <code class="computeroutput">n</code> is zero.</p></td>
130 </tr>
131 <tr>
132 <td><p>Subtractive motion</p></td>
133 <td><p>i -= n</p></td>
134 <td><p><span class="type">Iter &amp;</span></p></td>
135 <td><p>Equivalent to <code class="computeroutput">i+=(-n)</code></p></td>
136 </tr>
137 <tr>
138 <td><p>Subtractive motion (with integer offset)</p></td>
139 <td><p>i -= int_off</p></td>
140 <td><p><span class="type">Iter &amp;</span></p></td>
141 <td><p>Equivalent to <code class="computeroutput">i+=(-n)</code></p></td>
142 </tr>
143 <tr>
144 <td><p>Addition</p></td>
145 <td><p>i + n</p></td>
146 <td><p><span class="type">Iter</span></p></td>
147 <td><p>Equivalent to <code class="computeroutput">{Iter j = i; j += n; return j;}</code></p></td>
148 </tr>
149 <tr>
150 <td><p>Addition with integer</p></td>
151 <td><p>i + int_off</p></td>
152 <td><p><span class="type">Iter</span></p></td>
153 <td><p>Equivalent to <code class="computeroutput">{Iter j = i; j += n; return j;}</code></p></td>
154 </tr>
155 <tr>
156 <td><p>Addition (count first)</p></td>
157 <td><p>n + i</p></td>
158 <td><p><span class="type">Iter</span></p></td>
159 <td><p>Equivalent to <code class="computeroutput">i + n</code></p></td>
160 </tr>
161 <tr>
162 <td><p>Addition with integer (count first)</p></td>
163 <td><p>int_off + i</p></td>
164 <td><p><span class="type">Iter</span></p></td>
165 <td><p>Equivalent to <code class="computeroutput">i + n</code></p></td>
166 </tr>
167 <tr>
168 <td><p>Subtraction</p></td>
169 <td><p>i - n</p></td>
170 <td><p><span class="type">Iter</span></p></td>
171 <td><p>Equivalent to <code class="computeroutput">i + (-n)</code></p></td>
172 </tr>
173 <tr>
174 <td><p>Subtraction with integer</p></td>
175 <td><p>i - int_off</p></td>
176 <td><p><span class="type">Iter</span></p></td>
177 <td><p>Equivalent to <code class="computeroutput">i + (-n)</code></p></td>
178 </tr>
179 <tr>
180 <td><p>Distance</p></td>
181 <td><p>i - j</p></td>
182 <td><p><span class="type">difference_type</span></p></td>
183 <td><p>The number of times <code class="computeroutput">i</code> must be incremented (or
184     decremented if the result is negative) to reach <code class="computeroutput">j</code>.  Not
185     defined if <code class="computeroutput">j</code> is not reachable from
186     <code class="computeroutput">i</code>.</p></td>
187 </tr>
188 <tr>
189 <td><p>Element access</p></td>
190 <td><p>i[n]</p></td>
191 <td><p><span class="type">const-if-not-mutable value_type &amp;</span></p></td>
192 <td><p>Equivalent to <code class="computeroutput">*(i + n)</code></p></td>
193 </tr>
194 <tr>
195 <td><p>Element access with integer index</p></td>
196 <td><p>i[int_off]</p></td>
197 <td><p><span class="type">const-if-not-mutable value_type &amp;</span></p></td>
198 <td><p>Equivalent to <code class="computeroutput">*(i + n)</code></p></td>
199 </tr>
200 </tbody>
201 </table></div>
202 </div>
203 <div class="refsect1">
204 <a name="idp634521776"></a><h2>Complexity</h2>
205 <p>
206   All iterator operations must take amortized constant time.
207   </p>
208 </div>
209 <div class="refsect1">
210 <a name="idp634522528"></a><h2>Models</h2>
211 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
212 <li class="listitem"><span class="simplelist"><span class="type">T *</span></span></li>
213 <li class="listitem"><span class="simplelist"><span class="type">std::vector&lt;T&gt;::iterator</span></span></li>
214 <li class="listitem"><span class="simplelist"><span class="type">std::vector&lt;T&gt;::const_iterator</span></span></li>
215 <li class="listitem"><span class="simplelist"><span class="type">std::deque&lt;T&gt;::iterator</span></span></li>
216 <li class="listitem"><span class="simplelist"><span class="type">std::deque&lt;T&gt;::const_iterator</span></span></li>
217 </ul></div>
218 </div>
219 <div class="refsect1">
220 <a name="idp634527904"></a><h2>See also</h2>
221 <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p><a class="link" href="LessThanComparable.html" title="Concept LessThanComparable">LessThanComparable</a></p></li></ul></div>
222 </div>
223 </div>
224 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
225 <td align="left"></td>
226 <td align="right"><div class="copyright-footer">Copyright &#169; 2001, 2002 Indiana University<br>Copyright &#169; 2000, 2001 University of Notre Dame du Lac<br>Copyright &#169; 2000 Jeremy Siek, Lie-Quan Lee, Andrew Lumsdaine<br>Copyright &#169; 1996-1999 Silicon Graphics Computer Systems, Inc.<br>Copyright &#169; 1994 Hewlett-Packard Company<p>Distributed under the Boost Software License, Version 1.0.
227       (See accompanying file <code class="filename">LICENSE_1_0.txt</code> or copy at 
228       <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
229       </p>
230 <p>This product includes software developed at the University
231       of Notre Dame and the Pervasive Technology Labs at Indiana
232       University. For technical information contact Andrew Lumsdaine
233       at the Pervasive Technology Labs at Indiana University.  For
234       administrative and license questions contact the Advanced
235       Research and Technology Institute at 351 West 10th Street.
236       Indianapolis, Indiana 46202, phone 317-278-4100, fax
237       317-274-5902.</p>
238 <p>Some concepts based on versions from the MTL draft manual
239       and Boost Graph and Property Map documentation, the SGI Standard
240       Template Library documentation and the Hewlett-Packard STL,
241       under the following license: 
242         </p>
243 <div class="blockquote"><blockquote class="blockquote"><p>Permission to use, copy, modify, distribute and
244         sell this software and its documentation for any purpose is
245         hereby granted without fee, provided that the above copyright
246         notice appears in all copies and that both that copyright
247         notice and this permission notice appear in supporting
248         documentation.  Silicon Graphics makes no representations
249         about the suitability of this software for any purpose.  It is
250         provided "as is" without express or implied
251         warranty.</p></blockquote></div>
252 </div></td>
253 </tr></table>
254 <hr>
255 <div class="spirit-nav">
256 <a accesskey="p" href="BidirectionalIterator.html"><img src="../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="idp14900640-bb.html#concepts.reference"><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="DefaultConstructible.html"><img src="../../doc/src/images/next.png" alt="Next"></a>
257 </div>
258 </body>
259 </html>