Files
boost_range/doc/style.html

133 lines
4.9 KiB
HTML
Raw Normal View History

2004-07-30 02:56:01 +00:00
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
2004-08-05 19:37:40 +00:00
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Boost.Range Terminology and Style Guidelines </title>
<link rel="stylesheet" href="style.css" type="text/css">
2004-07-30 02:56:01 +00:00
</head>
2004-08-05 19:37:40 +00:00
<body>
<table border="0" >
<tr>
<td ><img src="../../../boost.png" border="0" ></td>
2004-08-10 09:56:55 +00:00
<td ><h1 align="center">Boost.Range </h1></td>
</tr>
2004-08-05 19:37:40 +00:00
</table>
<h2>Terminology and style guidelines </h2>
2004-08-10 09:56:55 +00:00
2004-08-05 19:37:40 +00:00
<p>
The use of a consistent terminology is as important for <a href="range.html">Range</a>s
2004-08-10 09:56:55 +00:00
and range-based algorithms as it is for iterators and iterator-based algorithms.
If a conventional set of names are adopted, we can avoid misunderstandings and
write generic function prototypes that are <i>self-documenting</i>.
2004-08-05 19:37:40 +00:00
</p>
<p>
2004-08-10 09:56:55 +00:00
Since ranges are characterized by a specific underlying iterator type, we get a
type of range for each type of iterator. Hence we can speak of the following
types of ranges:
2004-08-05 19:37:40 +00:00
<ul>
<li>
<i>Value access</i> category:
<ul>
<li>
2004-08-10 09:56:55 +00:00
Readable Range
2004-08-05 19:37:40 +00:00
<li>
2004-08-10 09:56:55 +00:00
Writeable Range
2004-08-05 19:37:40 +00:00
<li>
2004-08-10 09:56:55 +00:00
Swappable Range
2004-08-05 19:37:40 +00:00
<li>
2004-08-10 09:56:55 +00:00
Lvalue Range
2004-08-05 19:37:40 +00:00
</ul>
<li>
<i>Traversal</i> category:
<ul>
<li>
2004-08-16 22:47:16 +00:00
<a href="range.html#single_pass_range">Single Pass Range</a>
2004-08-05 19:37:40 +00:00
<li>
2004-08-16 22:47:16 +00:00
<a href="range.html#forward_range">Forward Range</a>
2004-08-05 19:37:40 +00:00
<li>
2004-08-16 22:47:16 +00:00
<a href="range.html#bidirectional_range">Bidirectional Range</a> <li>
<a href="range.html#random_access_range">Random Access Range</a> </ul>
2004-08-05 19:37:40 +00:00
</ul>
Notice how we have used the categories from the <a href=../../iterator/doc/new-iter-concepts.html>new
2004-08-12 10:58:13 +00:00
style iterators</a>.
2004-08-10 09:56:55 +00:00
2004-08-05 19:37:40 +00:00
<p>
2004-08-10 09:56:55 +00:00
Notice that an iterator (and therefore an range) has one <i>traversal</i>
2004-08-05 19:37:40 +00:00
property and one or more properties from the <i>value access</i> category. So in
2004-08-10 09:56:55 +00:00
reality we will mostly talk about mixtures such as
2004-08-05 19:37:40 +00:00
<ul>
<li>
2004-08-10 09:56:55 +00:00
Random Access Readable Writeable Range
2004-08-05 19:37:40 +00:00
<li>
2004-08-10 09:56:55 +00:00
Forward Lvalue Range
2004-08-05 19:37:40 +00:00
</ul>
2004-08-10 09:56:55 +00:00
By convention, we should always specify the <i>traversal</i> property first as
done above. This seems reasonable since there will only be one <i>traversal</i>
property, but perhaps many <i>value access</i> properties.
2004-08-05 19:37:40 +00:00
</p>
<p>
2004-08-12 10:58:13 +00:00
It might, however, be reasonable to specify only one category if the other
category does not matter. For example, the <a
href="utility_class.html#iter_range">iterator_range</a> can be constructed from
a Forward Range. This means that we do not care about what <i>value access</i>
properties the Range has. Similarly, a Readable Range will be one that has the
lowest possible <i>traversal</i> property (Single Pass).
</p>
<p>
As another example, consider how we specify the interface of <code>std::sort()</code>.
Algorithms are usually more cumbersome to specify the interface of since both <i>traversal</i>
and <i>value access</i> properties must be exactly defined. The iterator-based
version looks like this:
2004-08-05 19:37:40 +00:00
<pre>
2004-08-12 10:58:13 +00:00
<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><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><span class=identifier>RandomAccessTraversalReadableWritableIterator </span><span class=identifier>last </span><span class=special>);</span>
2004-07-30 02:56:01 +00:00
</pre>
2004-08-10 09:56:55 +00:00
For ranges the interface becomes
2004-08-05 19:37:40 +00:00
<pre>
2004-08-12 10:58:13 +00:00
<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><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>
2004-07-30 02:56:01 +00:00
</pre>
2004-08-05 19:37:40 +00:00
</p>
2004-08-12 10:58:13 +00:00
<p>
2004-08-05 19:37:40 +00:00
2004-08-12 10:58:13 +00:00
</p>
2004-08-05 19:37:40 +00:00
<hr>
<p>
&copy; <a name="Copyright" id="Copyright">Copyright</a> Thorsten Ottosen 2008.
2004-08-05 19:37:40 +00:00
</p>
<p>
Distributed under the Boost Software License, Version 1.0. (See
accompanying file LICENSE_1_0.txt or copy
at <a href=
"http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)
</p>
2004-08-05 19:37:40 +00:00
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
</body>
2004-07-30 02:56:01 +00:00
</html>