1 | <?xml version="1.0" encoding="utf-8" ?> |
---|
2 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
---|
3 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
---|
4 | <head> |
---|
5 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
---|
6 | <meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" /> |
---|
7 | <title>Random Access Traversal Concept</title> |
---|
8 | <link rel="stylesheet" href="default.css" type="text/css" /> |
---|
9 | </head> |
---|
10 | <body> |
---|
11 | <h1 class="title">Random Access Traversal Concept</h1> |
---|
12 | <div class="document" id="random-access-traversal-concept"> |
---|
13 | <p>A class or built-in type <tt class="literal"><span class="pre">X</span></tt> models the <em>Random Access Traversal</em> |
---|
14 | concept if the following expressions are valid and respect the stated |
---|
15 | semantics. In the table below, <tt class="literal"><span class="pre">Distance</span></tt> is |
---|
16 | <tt class="literal"><span class="pre">iterator_traits<X>::difference_type</span></tt> and <tt class="literal"><span class="pre">n</span></tt> represents a |
---|
17 | constant object of type <tt class="literal"><span class="pre">Distance</span></tt>.</p> |
---|
18 | <table border="1" class="table"> |
---|
19 | <colgroup> |
---|
20 | <col width="28%" /> |
---|
21 | <col width="30%" /> |
---|
22 | <col width="23%" /> |
---|
23 | <col width="20%" /> |
---|
24 | </colgroup> |
---|
25 | <thead valign="bottom"> |
---|
26 | <tr><th colspan="4">Random Access Traversal Iterator Requirements (in addition to Bidirectional Traversal)</th> |
---|
27 | </tr> |
---|
28 | <tr><th>Expression</th> |
---|
29 | <th>Return Type</th> |
---|
30 | <th>Operational Semantics</th> |
---|
31 | <th>Assertion/ |
---|
32 | Precondition</th> |
---|
33 | </tr> |
---|
34 | </thead> |
---|
35 | <tbody valign="top"> |
---|
36 | <tr><td><tt class="literal"><span class="pre">r</span> <span class="pre">+=</span> <span class="pre">n</span></tt></td> |
---|
37 | <td><tt class="literal"><span class="pre">X&</span></tt></td> |
---|
38 | <td><pre class="first last literal-block"> |
---|
39 | { |
---|
40 | Distance m = n; |
---|
41 | if (m >= 0) |
---|
42 | while (m--) |
---|
43 | ++r; |
---|
44 | else |
---|
45 | while (m++) |
---|
46 | --r; |
---|
47 | return r; |
---|
48 | } |
---|
49 | </pre> |
---|
50 | </td> |
---|
51 | <td> </td> |
---|
52 | </tr> |
---|
53 | <tr><td><tt class="literal"><span class="pre">a</span> <span class="pre">+</span> <span class="pre">n</span></tt>, <tt class="literal"><span class="pre">n</span> <span class="pre">+</span> <span class="pre">a</span></tt></td> |
---|
54 | <td><tt class="literal"><span class="pre">X</span></tt></td> |
---|
55 | <td><tt class="literal"><span class="pre">{</span> <span class="pre">X</span> <span class="pre">tmp</span> <span class="pre">=</span> <span class="pre">a;</span> <span class="pre">return</span> <span class="pre">tmp</span> |
---|
56 | <span class="pre">+=</span> <span class="pre">n;</span> <span class="pre">}</span></tt></td> |
---|
57 | <td> </td> |
---|
58 | </tr> |
---|
59 | <tr><td><tt class="literal"><span class="pre">r</span> <span class="pre">-=</span> <span class="pre">n</span></tt></td> |
---|
60 | <td><tt class="literal"><span class="pre">X&</span></tt></td> |
---|
61 | <td><tt class="literal"><span class="pre">return</span> <span class="pre">r</span> <span class="pre">+=</span> <span class="pre">-n</span></tt></td> |
---|
62 | <td> </td> |
---|
63 | </tr> |
---|
64 | <tr><td><tt class="literal"><span class="pre">a</span> <span class="pre">-</span> <span class="pre">n</span></tt></td> |
---|
65 | <td><tt class="literal"><span class="pre">X</span></tt></td> |
---|
66 | <td><tt class="literal"><span class="pre">{</span> <span class="pre">X</span> <span class="pre">tmp</span> <span class="pre">=</span> <span class="pre">a;</span> <span class="pre">return</span> <span class="pre">tmp</span> |
---|
67 | <span class="pre">-=</span> <span class="pre">n;</span> <span class="pre">}</span></tt></td> |
---|
68 | <td> </td> |
---|
69 | </tr> |
---|
70 | <tr><td><tt class="literal"><span class="pre">b</span> <span class="pre">-</span> <span class="pre">a</span></tt></td> |
---|
71 | <td><tt class="literal"><span class="pre">Distance</span></tt></td> |
---|
72 | <td><tt class="literal"><span class="pre">a</span> <span class="pre"><</span> <span class="pre">b</span> <span class="pre">?</span> <span class="pre">distance(a,b)</span> |
---|
73 | <span class="pre">:</span> <span class="pre">-distance(b,a)</span></tt></td> |
---|
74 | <td>pre: there exists a |
---|
75 | value <tt class="literal"><span class="pre">n</span></tt> of |
---|
76 | <tt class="literal"><span class="pre">Distance</span></tt> such that |
---|
77 | <tt class="literal"><span class="pre">a</span> <span class="pre">+</span> <span class="pre">n</span> <span class="pre">==</span> <span class="pre">b</span></tt>. <tt class="literal"><span class="pre">b</span> |
---|
78 | <span class="pre">==</span> <span class="pre">a</span> <span class="pre">+</span> <span class="pre">(b</span> <span class="pre">-</span> <span class="pre">a)</span></tt>.</td> |
---|
79 | </tr> |
---|
80 | <tr><td><tt class="literal"><span class="pre">a[n]</span></tt></td> |
---|
81 | <td>convertible to T</td> |
---|
82 | <td><tt class="literal"><span class="pre">*(a</span> <span class="pre">+</span> <span class="pre">n)</span></tt></td> |
---|
83 | <td>pre: a is a <em>Readable |
---|
84 | Iterator</em></td> |
---|
85 | </tr> |
---|
86 | <tr><td><tt class="literal"><span class="pre">a[n]</span> <span class="pre">=</span> <span class="pre">v</span></tt></td> |
---|
87 | <td>convertible to T</td> |
---|
88 | <td><tt class="literal"><span class="pre">*(a</span> <span class="pre">+</span> <span class="pre">n)</span> <span class="pre">=</span> <span class="pre">v</span></tt></td> |
---|
89 | <td>pre: a is a <em>Writable |
---|
90 | iterator</em></td> |
---|
91 | </tr> |
---|
92 | <tr><td><tt class="literal"><span class="pre">a</span> <span class="pre"><</span> <span class="pre">b</span></tt></td> |
---|
93 | <td>convertible to <tt class="literal"><span class="pre">bool</span></tt></td> |
---|
94 | <td><tt class="literal"><span class="pre">b</span> <span class="pre">-</span> <span class="pre">a</span> <span class="pre">></span> <span class="pre">0</span></tt></td> |
---|
95 | <td><tt class="literal"><span class="pre"><</span></tt> is a total |
---|
96 | ordering relation</td> |
---|
97 | </tr> |
---|
98 | <tr><td><tt class="literal"><span class="pre">a</span> <span class="pre">></span> <span class="pre">b</span></tt></td> |
---|
99 | <td>convertible to <tt class="literal"><span class="pre">bool</span></tt></td> |
---|
100 | <td><tt class="literal"><span class="pre">b</span> <span class="pre"><</span> <span class="pre">a</span></tt></td> |
---|
101 | <td><tt class="literal"><span class="pre">></span></tt> is a total |
---|
102 | ordering relation</td> |
---|
103 | </tr> |
---|
104 | <tr><td><tt class="literal"><span class="pre">a</span> <span class="pre">>=</span> <span class="pre">b</span></tt></td> |
---|
105 | <td>convertible to <tt class="literal"><span class="pre">bool</span></tt></td> |
---|
106 | <td><tt class="literal"><span class="pre">!(a</span> <span class="pre"><</span> <span class="pre">b)</span></tt></td> |
---|
107 | <td> </td> |
---|
108 | </tr> |
---|
109 | <tr><td><tt class="literal"><span class="pre">a</span> <span class="pre"><=</span> <span class="pre">b</span></tt></td> |
---|
110 | <td>convertible to <tt class="literal"><span class="pre">bool</span></tt></td> |
---|
111 | <td><tt class="literal"><span class="pre">!(a</span> <span class="pre">></span> <span class="pre">b)</span></tt></td> |
---|
112 | <td> </td> |
---|
113 | </tr> |
---|
114 | <tr><td><tt class="literal"><span class="pre">iterator_traversal<X>::type</span></tt></td> |
---|
115 | <td>Convertible to |
---|
116 | <tt class="literal"><span class="pre">random_access_traversal_tag</span></tt></td> |
---|
117 | <td> </td> |
---|
118 | <td> </td> |
---|
119 | </tr> |
---|
120 | </tbody> |
---|
121 | </table> |
---|
122 | </div> |
---|
123 | <hr class="footer" /> |
---|
124 | <div class="footer"> |
---|
125 | <a class="reference" href="RandomAccessTraversal.rst">View document source</a>. |
---|
126 | Generated by <a class="reference" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source. |
---|
127 | </div> |
---|
128 | </body> |
---|
129 | </html> |
---|