Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/range/doc/style.html @ 12

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

added boost

  • Property svn:executable set to *
File size: 4.6 KB
Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
2
3<html>
4<head>
5    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
6    <title>Boost.Range Terminology and Style Guidelines </title>
7    <link rel="stylesheet" href="style.css" type="text/css">
8</head>
9
10    <body>
11
12    <table border="0" >
13        <tr>
14            <td ><img src="../../../boost.png" border="0" ></td>
15            <td ><h1 align="center">Boost.Range </h1></td>
16        </tr>
17    </table>
18
19    <h2>Terminology and style guidelines </h2>
20
21    <p>
22    The use of a consistent terminology is as important for <a href="range.html">Range</a>s
23    and range-based algorithms as it is for iterators and iterator-based algorithms.
24    If a conventional set of names are adopted, we can avoid misunderstandings and
25    write generic function prototypes that are <i>self-documenting</i>.
26    </p>
27
28    <p>
29    Since ranges are characterized by a specific underlying iterator type, we get a
30    type of range for each type of iterator. Hence we can speak of the following
31    types of ranges:
32    <ul>
33        <li>
34            <i>Value access</i> category:
35            <ul>
36                <li>
37                    Readable Range
38                <li>
39                    Writeable Range
40                <li>
41                    Swappable Range
42                <li>
43                    Lvalue Range
44            </ul>
45        <li>
46            <i>Traversal</i> category:
47            <ul>
48                <li>
49                    <a href="range.html#single_pass_range">Single Pass Range</a>
50                <li>
51                    <a href="range.html#forward_range">Forward Range</a>
52                <li>
53                    <a href="range.html#bidirectional_range">Bidirectional Range</a> <li>
54                    <a href="range.html#random_access_range">Random Access Range</a> </ul>
55    </ul>
56    Notice how we have used the categories from the <a href=../../iterator/doc/new-iter-concepts.html>new
57    style iterators</a>.
58
59    <p>
60    Notice that an iterator (and therefore an range) has one <i>traversal</i> 
61    property and one or more properties from the <i>value access</i> category. So in
62    reality we will mostly talk about mixtures such as
63    <ul>
64        <li>
65            Random Access Readable Writeable Range
66        <li>
67            Forward Lvalue Range
68    </ul>
69    By convention, we should always specify the <i>traversal</i> property first as
70    done above. This seems reasonable since there will only be one <i>traversal</i> 
71    property, but perhaps many <i>value access</i> properties.
72    </p>
73
74    <p>
75    It might, however, be reasonable to specify only one category if the other
76    category does not matter. For example, the <a
77   href="utility_class.html#iter_range">iterator_range</a> can be constructed from
78   a Forward Range. This means that we do not care about what <i>value access</i> 
79   properties the Range has. Similarly, a Readable Range will be one that has the
80   lowest possible <i>traversal</i> property (Single Pass).
81    </p>
82
83    <p>
84    As another example, consider how we specify the interface of <code>std::sort()</code>.
85    Algorithms are usually more cumbersome to specify the interface of since both <i>traversal</i> 
86    and <i>value access</i> properties must be exactly defined. The iterator-based
87        version looks like this:
88
89    <pre>
90   <span class=keyword>template</span><span class=special>&lt; </span><span class=keyword>class </span><span class=identifier>RandomAccessTraversalReadableWritableIterator </span><span class=special>&gt;
91   </span><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>,
92              </span><span class=identifier>RandomAccessTraversalReadableWritableIterator </span><span class=identifier>last </span><span class=special>);</span>
93   </pre>
94    For ranges the interface becomes
95
96    <pre>
97   <span class=keyword>template</span><span class=special>&lt; </span><span class=keyword>class </span><span class=identifier>RandomAccessReadableWritableRange </span><span class=special>&gt;
98   </span><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>
99   </pre>
100    </p>
101    <p>
102
103    </p>
104
105    <hr>
106    <p>
107    (C) Copyright Thorsten Ottosen 2003-2004
108    </p>
109
110    <br>
111    <br>
112    <br>
113    <br>
114    <br>
115    <br>
116    <br>
117    <br>
118    <br>
119    <br>
120    <br>
121    <br>
122
123
124    </body>
125</html>
126
Note: See TracBrowser for help on using the repository browser.