• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>Terminology and style guidelines</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="../index.html" title="Chapter 1. Range 2.0">
9<link rel="prev" href="reference/extending/method_3/method_3_2.html" title="Method 3.2: Implement a Range Adaptor with arguments">
10<link rel="next" href="headers.html" title="Library Headers">
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="reference/extending/method_3/method_3_2.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.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="headers.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
24</div>
25<div class="section">
26<div class="titlepage"><div><div><h2 class="title" style="clear: both">
27<a name="range.style_guide"></a><a class="link" href="style_guide.html" title="Terminology and style guidelines">Terminology and style guidelines</a>
28</h2></div></div></div>
29<p>
30      The use of a consistent terminology is as important for <a class="link" href="concepts.html" title="Range Concepts">Ranges</a>
31      and range-based algorithms as it is for iterators and iterator-based algorithms.
32      If a conventional set of names are adopted, we can avoid misunderstandings
33      and write generic function prototypes that are <span class="bold"><strong><span class="emphasis"><em>self-documenting</em></span></strong></span>.
34    </p>
35<p>
36      Since ranges are characterized by a specific underlying iterator type, we get
37      a type of range for each type of iterator. Hence we can speak of the following
38      types of ranges:
39    </p>
40<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
41<li class="listitem">
42          <span class="bold"><strong><span class="emphasis"><em>Value access</em></span></strong></span> category:
43          <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; ">
44<li class="listitem">
45                Readable Range
46              </li>
47<li class="listitem">
48                Writeable Range
49              </li>
50<li class="listitem">
51                Swappable Range
52              </li>
53<li class="listitem">
54                Lvalue Range
55              </li>
56</ul></div>
57        </li>
58<li class="listitem">
59          <span class="bold"><strong><span class="emphasis"><em>Traversal</em></span></strong></span> category:
60          <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; ">
61<li class="listitem">
62                <a class="link" href="concepts/single_pass_range.html" title="Single Pass Range">Single Pass Range</a>
63              </li>
64<li class="listitem">
65                <a class="link" href="concepts/forward_range.html" title="Forward Range">Forward Range</a>
66              </li>
67<li class="listitem">
68                <a class="link" href="concepts/bidirectional_range.html" title="Bidirectional Range">Bidirectional
69                Range</a>
70              </li>
71<li class="listitem">
72                <a class="link" href="concepts/random_access_range.html" title="Random Access Range">Random Access
73                Range</a>
74              </li>
75</ul></div>
76        </li>
77</ul></div>
78<p>
79      Notice how we have used the categories from the <a href="../../../../../libs/iterator/doc/new-iter-concepts.html" target="_top">new
80      style iterators</a>.
81    </p>
82<p>
83      Notice that an iterator (and therefore an range) has one <span class="bold"><strong><span class="emphasis"><em>traversal</em></span></strong></span>
84      property and one or more properties from the <span class="bold"><strong><span class="emphasis"><em>value
85      access</em></span></strong></span> category. So in reality we will mostly talk about
86      mixtures such as
87    </p>
88<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
89<li class="listitem">
90          Random Access Readable Writeable Range
91        </li>
92<li class="listitem">
93          Forward Lvalue Range
94        </li>
95</ul></div>
96<p>
97      By convention, we should always specify the <span class="bold"><strong><span class="emphasis"><em>traversal</em></span></strong></span>
98      property first as done above. This seems reasonable since there will only be
99      one <span class="bold"><strong><span class="emphasis"><em>traversal</em></span></strong></span> property,
100      but perhaps many <span class="bold"><strong><span class="emphasis"><em>value access</em></span></strong></span>
101      properties.
102    </p>
103<p>
104      It might, however, be reasonable to specify only one category if the other
105      category does not matter. For example, the <a class="link" href="reference/utilities/iterator_range.html" title="Class iterator_range"><code class="computeroutput"><span class="identifier">iterator_range</span></code></a> can be constructed
106      from a Forward Range. This means that we do not care about what <span class="bold"><strong><span class="emphasis"><em>value
107      access</em></span></strong></span> properties the Range has. Similarly, a Readable
108      Range will be one that has the lowest possible <span class="bold"><strong><span class="emphasis"><em>traversal</em></span></strong></span>
109      property (Single Pass).
110    </p>
111<p>
112      As another example, consider how we specify the interface of <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">sort</span><span class="special">()</span></code>. Algorithms are usually more cumbersome to
113      specify the interface of since both <span class="bold"><strong><span class="emphasis"><em>traversal</em></span></strong></span>
114      and <span class="bold"><strong><span class="emphasis"><em>value access</em></span></strong></span> properties
115      must be exactly defined. The iterator-based version looks like this:
116    </p>
117<p>
118</p>
119<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">class</span> <span class="identifier">RandomAccessTraversalReadableWritableIterator</span> <span class="special">&gt;</span>
120<span class="keyword">void</span> <span class="identifier">sort</span><span class="special">(</span> <span class="identifier">RandomAccessTraversalReadableWritableIterator</span> <span class="identifier">first</span><span class="special">,</span>
121           <span class="identifier">RandomAccessTraversalReadableWritableIterator</span> <span class="identifier">last</span> <span class="special">);</span>
122</pre>
123<p>
124    </p>
125<p>
126      For ranges the interface becomes
127    </p>
128<p>
129</p>
130<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span> <span class="keyword">class</span> <span class="identifier">RandomAccessReadableWritableRange</span> <span class="special">&gt;</span>
131<span class="keyword">void</span> <span class="identifier">sort</span><span class="special">(</span> <span class="identifier">RandomAccessReadableWritableRange</span><span class="special">&amp;</span> <span class="identifier">r</span> <span class="special">);</span>
132</pre>
133<p>
134    </p>
135</div>
136<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
137<td align="left"></td>
138<td align="right"><div class="copyright-footer">Copyright © 2003-2010 Thorsten Ottosen,
139      Neil Groves<p>
140        Distributed under the Boost Software License, Version 1.0. (See accompanying
141        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>)
142      </p>
143</div></td>
144</tr></table>
145<hr>
146<div class="spirit-nav">
147<a accesskey="p" href="reference/extending/method_3/method_3_2.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.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="headers.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
148</div>
149</body>
150</html>
151