Files
boost_range/doc/range.html

494 lines
17 KiB
HTML
Raw Normal View History

2004-06-29 02:58:13 +00:00
<HTML>
<!--
-- Copyright (c) Jeremy Siek 2000
--
-- Permission to use, copy, modify, distribute and sell this software
-- and its documentation for any purpose is hereby granted without fee,
-- provided that the above copyright notice appears in all copies and
-- that both that copyright notice and this permission notice appear
-- in supporting documentation. Silicon Graphics makes no
-- representations about the suitability of this software for any
-- purpose. It is provided "as is" without express or implied warranty.
-->
<Head>
2004-08-05 19:37:40 +00:00
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<Title>Range Concepts</Title>
<link rel="stylesheet" href="style.css" type="text/css">
2004-06-29 02:58:13 +00:00
</HEAD>
2004-08-10 09:56:55 +00:00
<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>
</table>
<h2>Range concepts </h2>
<ul>
<li>
<a href="#overview">Overview</a>
<li>
<a href="#single_pass_range">Single Pass Range</a>
<li>
<a href="#forward_range">Forward Range</a>
<li>
<a href="#bidirectional_range">Bidirectional Range</a>
<li>
<a href="#random_access_range">Random Access Range</a>
</ul>
<a name="overview"></a>
<hr>
<h3>Overview</h3>
<p>
A Range is a <i>concept</i> similar to the STL <a
href="http://www.sgi.com/Technology/STL/Container.html">Container</a> concept. A
Range provides iterators for accessing a closed-open range
<code>[first,one_past_last)</code> of elements and provides
information about the number of elements in the Range. However, a Range has
fewer requirements than a Container.
</p>
<p>
The motivation for the Range concept is
that there are many useful Container-like types that do not meet the full
requirements of Container, and many algorithms that can be written with this
reduced set of requirements. In particular, a Range does not necessarily
<ul>
<li>
own the elements that can be accessed through it,
<li>
have copy semantics,
<!--
<li>
require that the associated reference type is a real C++ reference.
-->
</ul>
2004-08-24 15:58:01 +00:00
Because of the second requirement, a Range object must be passed by
(const or non-const) reference in generic code.
2004-08-10 09:56:55 +00:00
</p>
<p>
The operations that can be performed on a Range is dependent on the
<a href="../../iterator/doc/new-iter-concepts.html#iterator-traversal-concepts-lib-iterator-traversal">traversal
category</a> of the underlying iterator type. Therefore
the range concepts are named to reflect which traversal category its
iterators support. See also <a href="style.html">terminology and style guidelines.</a>
for more information about naming of ranges.</p>
2004-08-12 10:58:13 +00:00
<p> The concepts described below specifies associated types as
<a href="../../mpl/doc/index.html#metafunctions">metafunctions</a> and all
functions as free-standing functions to allow for a layer of indirection. </p>
2004-08-10 09:56:55 +00:00
2005-05-03 22:39:49 +00:00
<p><i>Notice that these metafunctions must be defined in namespace </i>
<code>boost</code></p>
2004-08-10 09:56:55 +00:00
<hr>
<a name="single_pass_range">
<H2>Single Pass Range</H2>
<h3>Notation</h3>
<Table>
2004-08-05 19:37:40 +00:00
<TR>
2004-08-10 09:56:55 +00:00
<TD VAlign="top"><code>X</code></TD>
<TD VAlign="top">A type that is a model of Single Pass Range.</TD>
</TR>
<TR>
<TD VAlign="top"><code>a</code></TD>
<TD VAlign="top">Object of type <code>X</code>.</TD>
</TR>
</table>
<h3>Description</h3>
<p>
2004-08-16 22:47:16 +00:00
A range X where <code>range_iterator&lt;X>::type</code> is a model of <a
2004-08-10 09:56:55 +00:00
href="../../iterator/doc/new-iter-concepts.html#single-pass-iterators-lib-single-pass-iterators">
Single Pass Iterator</a>
</p>
<h3>Associated types</h3>
<table border="1" cellpadding="5">
<TR>
<TD VAlign="top">Value type</TD>
2004-08-16 22:47:16 +00:00
<TD VAlign="top"><code>range_value&lt;X>::type</code></TD>
2004-08-10 09:56:55 +00:00
<TD VAlign="top">The type of the object stored in a Range.
</TR>
<TR>
<TD VAlign="top">Iterator type</TD>
2004-08-16 22:47:16 +00:00
<TD VAlign="top"><code>range_iterator&lt;X>::type</code></TD>
2004-08-10 09:56:55 +00:00
<TD VAlign="top">The type of iterator used to iterate through a Range's elements.
The iterator's value type is expected to be the Range's value type. A
conversion from the iterator type to the const iterator type must exist.
</TR>
<TR>
<TD VAlign="top">Const iterator type</TD>
2004-08-16 22:47:16 +00:00
<TD VAlign="top"><code>range_const_iterator&lt;X>::type</code></TD>
2004-08-10 09:56:55 +00:00
<TD VAlign="top">A type of iterator that may be used to examine, but not to
modify, a Range's elements.</TD>
</TR>
<!--
<TR>
<TD VAlign="top">Reference type</TD>
<TD VAlign="top"><code>reference_of&lt;X>::type</code></TD>
<TD VAlign="top">A type that behaves like a reference to the Range's value type. <a href="#1">[1]</a></TD>
</TR>
-->
</table>
<h3>Valid expressions</h3>
The following expressions must be valid.
<p>
<Table border="1" cellpadding="5">
<TR>
<TH>Name</TH>
<TH>Expression</TH>
<TH>Return type</TH>
</TR>
<TR>
<TD VAlign="top">Beginning of range</TD>
<TD VAlign="top"><code>begin(a)</code></TD>
2004-08-16 22:47:16 +00:00
<TD VAlign="top"><code>range_iterator&lt;X>::type</code> if
<code>a</code> is mutable, <code>range_const_iterator&lt;X>::type</code>
2004-08-10 09:56:55 +00:00
otherwise</TD> </TR>
<TR>
<TD VAlign="top">End of range</TD>
<TD VAlign="top"><code>end(a)</code></TD>
2004-08-16 22:47:16 +00:00
<TD VAlign="top"><code>range_iterator&lt;X>::type</code> if
<code>a</code> is mutable, <code>range_const_iterator&lt;X>::type</code>
2004-08-10 09:56:55 +00:00
otherwise</TD>
</TR>
<tr>
<TD VAlign="top">Is range empty?</TD>
<TD VAlign="top"><code>empty(a)</code></TD>
<TD VAlign="top">Convertible to <code>bool</code></TD>
</TR>
</table>
<h3>Expression semantics</h3>
<Table border>
<TR>
<TH>Expression</TH>
<TH>Semantics</TH>
<TH>Postcondition</TH>
</TR>
<TR>
<TD VAlign="top"><code>begin(a)</code></TD>
2004-08-05 19:37:40 +00:00
<TD VAlign="top">Returns an iterator pointing to the first element in the Range.</TD>
2004-08-10 09:56:55 +00:00
<TD VAlign="top"><code>begin(a)</code> is either dereferenceable or past-the-end.
It is past-the-end if and only if <code>size(a) == 0</code>.</TD>
2004-08-05 19:37:40 +00:00
</TR>
<TR>
2004-08-10 09:56:55 +00:00
<TD VAlign="top"><code>end(a)</code></TD>
2004-08-05 19:37:40 +00:00
<TD VAlign="top">Returns an iterator pointing one past the last element in the
Range.</TD>
2004-08-10 09:56:55 +00:00
<TD VAlign="top"><code>end(a)</code> is past-the-end.</TD>
</TR>
<TR>
<TD VAlign="top"><code>empty(a)</code></TD>
<TD VAlign="top">Equivalent to <code>begin(a) == end(a)</code>. (But possibly
faster.)</TD>
<TD VAlign="top">&nbsp;-&nbsp;</TD>
</TR>
</table>
<h3>Complexity guarantees</h3>
All three functions are at most amortized linear time. For most practical
purposes, one can expect <code>begin(a)</code>, <code>end(a)</code> and <code>empty(a)</code>
to be amortized constant time.
<h3>Invariants</h3>
<Table border>
<TR>
<TD VAlign="top">Valid range</TD>
<TD VAlign="top">For any Range <code>a</code>, <code>[begin(a),end(a))</code> is
a valid range, that is, <code>end(a)</code> is reachable from <code>begin(a)</code>
in a finite number of increments.</TD>
</TR>
<TR>
<TD VAlign="top">Completeness</TD>
<TD VAlign="top">An algorithm that iterates through the range <code>[begin(a),end(a))</code>
will pass through every element of <code>a</code>.</TD>
</tr>
</table>
<h3>See also</h3>
<p>
<A href="http://www.sgi.com/Technology/STL/Container.html">Container</A>
</p>
2005-05-03 22:39:49 +00:00
<p> <a href="boost_range.html#range_value">implementation of
metafunctions </a></p>
<p> <a href="boost_range.html#begin">implementation of
functions </a></p>
2004-08-10 09:56:55 +00:00
<hr>
<a name=forward_range><h2>Forward Range</h2>
<h3>Notation</h3>
<Table>
<TR>
<TD VAlign="top"><code>X</code></TD>
<TD VAlign="top">A type that is a model of Forward Range.</TD>
2004-08-05 19:37:40 +00:00
</TR>
<TR>
2004-08-10 09:56:55 +00:00
<TD VAlign="top"><code>a</code></TD>
<TD VAlign="top">Object of type <code>X</code>.</TD>
</TR>
</table>
<h3>Description</h3>
<p>
2004-08-16 22:47:16 +00:00
A range <code>X</code> where <code>range_iterator&lt;X>::type</code> is a model
2004-08-10 09:56:55 +00:00
of <a
href="../../iterator/doc/new-iter-concepts.html#forward-traversal-iterators-lib-forward-traversal-iterators">Forward Traversal Iterator</a>
</p>
<h3>Refinement of</h3> <a href="#single_pass_range">Single Pass
Range</a>
<h3>Associated types</h3>
<table cellpadding="5" border="1">
<TR>
<TD VAlign="top">Distance type</TD>
2004-08-16 22:47:16 +00:00
<TD VAlign="top"><code>range_difference&lt;X>::type</code></TD>
2004-08-10 09:56:55 +00:00
<TD VAlign="top">A signed integral type used to represent the distance between
two of the Range's iterators. This type must be the same as the iterator's
distance type.</TD>
</TR>
<TR>
<TD VAlign="top">Size type</TD>
2004-08-16 22:47:16 +00:00
<TD VAlign="top"><code>range_size&lt;X>::type</code></TD>
2004-08-10 09:56:55 +00:00
<TD VAlign="top">An unsigned integral type that can represent any nonnegative
value of the Range's distance type.</TD>
</tr>
</table>
<h3>Valid expressions</h3>
<table border="1" cellpadding="5">
<tr>
<th>Name</th>
<th>Expression</th>
<th>Return type</th>
</tr>
<TR>
<TD VAlign="top">Size of range</TD>
<TD VAlign="top"><code>size(a)</code></TD>
2004-08-16 22:47:16 +00:00
<TD VAlign="top"><code>range_size&lt;X>::type</code></TD>
2004-08-10 09:56:55 +00:00
</TR>
</table>
<h3>Expression semantics </h3>
<table border="1" cellpadding="5">
<TR>
<TH>Expression</TH>
<TH>Semantics</TH>
<TH>Postcondition</TH>
</TR>
<tr>
<TD VAlign="top"><code>size(a)</code></TD>
<TD VAlign="top">Returns the size of the Range, that is, its number
of elements. Note <code>size(a) == 0u</code> is equivalent to
<code>empty(a).</code></TD>
<TD VAlign="top"><code>size(a) &gt;= 0</TD>
</TR>
</table>
<h3>Complexity guarantees</h3>
<p><code>size(a)</code> is at most amortized linear time.</p>
<h3>Invariants</h3>
<p>
<Table border="1" cellpadding="5">
<TR>
<TD VAlign="top">Range size</TD>
<TD VAlign="top"><code>size(a)</code> is equal to the distance from <code>begin(a)</code>
to <code>end(a)</code>.</TD> </table>
</p>
2005-05-03 22:39:49 +00:00
<h3>See also</h3>
<p> <a href="boost_range.html#range_difference">implementation of
metafunctions </a></p>
<p> <a href="boost_range.html#size">implementation of
functions </a></p>
2004-08-10 09:56:55 +00:00
<hr>
2005-05-03 22:39:49 +00:00
<a name="bidirectional_range"><h2>Bidirectional Range</h2>
2004-08-10 09:56:55 +00:00
<h3>Notation</h3>
<Table>
<TR>
<TD VAlign="top"><code>X</code></TD>
<TD VAlign="top">A type that is a model of Bidirectional Range.</TD>
</TR>
<TR>
<TD VAlign="top"><code>a</code></TD>
<TD VAlign="top">Object of type <code>X</code>.</TD>
</TR>
</table>
<h3>Description</h3> This concept provides access to iterators that traverse in
both directions (forward and reverse). The
2004-08-16 22:47:16 +00:00
<code>range_iterator&lt;X>::type</code> iterator must meet all of the requirements
2004-08-10 09:56:55 +00:00
of <a
href="../../iterator/doc/new-iter-concepts.html#bidirectional-traversal-iterator
s-lib-bidirectional-traversal-iterators">Bidirectional Traversal Iterator.</a>
<h3>Refinement of</h3> <a href="#forward_range">Forward Range</a>
<h3>Associated types</h3>
<Table border>
<TR>
<TD VAlign="top">Reverse Iterator type</TD>
2004-08-16 22:47:16 +00:00
<TD VAlign="top"><code>range_reverse_iterator&lt;X>::type</code></TD>
2004-08-10 09:56:55 +00:00
<TD VAlign="top">The type of iterator used to iterate through a Range's elements
in reverse order. The iterator's value type is expected to be the Range's value
type. A conversion from the reverse iterator type to the const reverse iterator
type must exist. </TD>
</TR>
<TR>
<TD VAlign="top">Const reverse iterator type</TD>
<TD
2004-08-16 22:47:16 +00:00
VAlign="top"><code>range_const_reverse_iterator&ltX>::type</code></TD>
2004-08-10 09:56:55 +00:00
<TD VAlign="top">A type of reverse iterator that may be used to examine, but not
to modify, a Range's elements.</TD>
</TR>
</table>
<h3>Valid expressions</h3>
<Table border>
<TR>
<TH>Name</TH>
<TH>Expression</TH>
<TH>Return type</TH>
<TH>Semantics</TH>
</TR>
<TR>
<TD VAlign="top">Beginning of range</TD>
<TD VAlign="top"><code>rbegin(a)</code></TD>
2004-08-16 22:47:16 +00:00
<TD VAlign="top"><code>range_reverse_iterator&lt;X>::type</code> if
<code>a</code> is mutable, <code>range_const_reverse_iterator&lt;X>::type</code>
2004-08-10 09:56:55 +00:00
otherwise.</TD>
<TD VAlign="top">Equivalent to
2004-08-16 22:47:16 +00:00
<code>range_reverse_iterator&lt;X>::type(end(a))</code>.</TD> </TR>
2004-08-10 09:56:55 +00:00
<TR>
<TD VAlign="top">End of range</TD>
<TD VAlign="top"><code>rend(a)</code></TD>
2004-08-16 22:47:16 +00:00
<TD VAlign="top"><code>range_reverse_iterator&lt;X>::type</code> if
<code>a</code> is mutable, <code>range_const_reverse_iterator&lt;X>::type</code>
2004-08-10 09:56:55 +00:00
otherwise.</TD>
<TD VAlign="top">Equivalent to
2004-08-16 22:47:16 +00:00
<code>range_reverse_iterator&lt;X>::type(begin(a))</code>.</TD> </tr>
2004-08-10 09:56:55 +00:00
</table>
<h3>Complexity guarantees</h3>
<code>rbegin(a)</code> has the same complexity as <code>end(a)</code> and <code>rend(a)</code>
has the same complexity as <code>begin(a)</code> from <a
href="#forward_range">Forward Range</a>.
<h3>Invariants</h3>
<p>
<Table border="1" cellpadding="5">
<TR>
<TD VAlign="top">Valid reverse range</TD>
<TD VAlign="top">For any Bidirectional Range <code>a</code>, <code>[rbegin(a),rend(a))</code>
is a valid range, that is, <code>rend(a)</code> is reachable from <code>rbegin(a)</code>
in a finite number of increments.</TD>
2004-08-05 19:37:40 +00:00
</TR>
<TR>
2004-08-10 09:56:55 +00:00
<TD VAlign="top">Completeness</TD>
<TD VAlign="top">An algorithm that iterates through the range <code>[rbegin(a),rend(a))</code>
will pass through every element of <code>a</code>.</TD>
</tr>
</table>
</p>
2005-05-03 22:39:49 +00:00
<h3>See also</h3>
<p> <a href="boost_range.html#range_reverse_iterator">implementation of metafunctions </a></p>
<p> <a href="boost_range.html#rbegin">implementation of
functions </a></p>
2004-08-10 09:56:55 +00:00
<hr>
<a name=random_access_range><h2>Random Access Range</h2> <h3>Description</h3>
<p>
2004-08-16 22:47:16 +00:00
A range <code>X</code> where <code>range_iterator&lt;X>::type</code> is a model
2004-08-10 09:56:55 +00:00
of <a
2004-10-06 18:19:13 +00:00
href="../../iterator/doc/new-iter-concepts.html#random-access-traversal-iterators
2004-08-10 09:56:55 +00:00
-lib-random-access-traversal-iterators">Random Access Traversal Iterator</a>
</p>
<h3>Refinement of</h3>
<p>
<a href="#bidirectional_range">Bidirectional Range</a>
</p>
<hr>
<!--
<h3>Notes</h3>
<P>
<A name="1">[1]</A>
The reference type does not have to be a real C++ reference. The requirements of
the reference type is that it <i>behaves</i> like a real reference. Hence the
reference type must be convertible to the value_type and assignment through
<br>
<br>
<HR>
<br>
-->
<TABLE>
<TR valign="top">
<TD nowrap>Copyright &copy 2000</TD>
<TD><A HREF=http://www.boost.org/people/jeremy_siek.htm>Jeremy Siek</A>
2004-08-05 19:37:40 +00:00
</TR>
2004-08-10 09:56:55 +00:00
<tr >
<TD nowrap>Copyright &copy 2004</TD>
<TD>Thorsten Ottosen.
</TABLE>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
</BODY>
2004-08-05 19:37:40 +00:00
</HTML>