Files
range/doc/faq.html

139 lines
6.2 KiB
HTML
Raw Normal View History

2004-08-05 19:37:40 +00:00
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Boost.Range FAQ </title>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body>
<table border="0" >
<tr>
<td ><img src="../../../boost.png" border="0" ></td>
2004-08-05 19:37:40 +00:00
<td ><h1 align="center">Boost.Range</h1></td>
</tr>
</table>
<p>
2004-08-10 09:56:55 +00:00
<h2 >FAQ</h2> <a name="FAQ" ></a>
2004-08-05 19:37:40 +00:00
<ol >
<li >
<i>Why is there no difference between <code >range_iterator&lt;C&gt;::type</code>
2004-08-16 22:47:16 +00:00
and <code >range_const_iterator&lt;C&gt;::type</code> for <code>std::pair&lt;iterator, iterator&gt;</code></i>.
2004-08-05 19:37:40 +00:00
</li>
<p >
In general it is not possible nor desirable to find a corresponding <code >const_iterator</code>.
When it is possible to come up with one, the client might choose to construct a <code >std::pair&lt;const_iterator,const_iterator&gt;</code>
2004-08-05 19:37:40 +00:00
object.
</p>
2004-08-12 10:58:13 +00:00
<p>
Note that an <a href="utility_class.html#iter_range">iterator_range</a>
is somewhat more convenient than a <code>pair</code> and that a <a
href="utility_class.html#sub_range"><code>sub_range</code></a> does
2004-08-24 15:58:01 +00:00
propagate const-ness. </p>
2004-08-05 19:37:40 +00:00
<li >
2004-08-10 09:56:55 +00:00
<i>Why is there not supplied more types or more functions?</i>
2004-08-05 19:37:40 +00:00
<p >
The library has been kept small because its current interface will
2004-08-24 15:58:01 +00:00
serve most
purposes. If and when a genuine need arises for more functionality, it can be
2004-08-10 09:56:55 +00:00
implemented.
2004-08-05 19:37:40 +00:00
</p>
</li>
<li >
2004-08-10 09:56:55 +00:00
<i>How should I implement generic algorithms for ranges?</i>
2004-08-05 19:37:40 +00:00
<p >
One should always start with a generic algorithm that takes two iterators (or
more) as input. Then use Boost.Range to build handier versions on top of the
iterator based algorithm. Please notice that once the range version of the
algorithm is done, it makes sense <i>not</i> to expose the iterator version in
2004-08-10 09:56:55 +00:00
the public interface.
2004-08-05 19:37:40 +00:00
</p>
</li>
2004-08-10 09:56:55 +00:00
<li>
<i>Why is there no Incrementable Range concept?</i>
<p>
Even though we speak of incrementable iterators, it would not make
much sense for ranges; for example, we cannot determine the size and
emptiness of a range since we cannot even compare
its iterators.
2004-08-10 09:56:55 +00:00
</p>
2004-08-24 15:58:01 +00:00
<p>
Note also that incrementable iterators are derived from output
2004-08-24 15:58:01 +00:00
iterators and so there exist no output range.
</p>
</li>
2004-08-24 15:58:01 +00:00
<!--
2004-08-10 09:56:55 +00:00
<li>
<i>Should I use qualified syntax, for example
2004-08-12 10:58:13 +00:00
<blockquote><pre>
<span class=identifier>boost</span><span class=special>::</span><span class=identifier>begin</span><span class=special>( </span><span class=identifier>r </span><span class=special>); </span>
</pre></blockquote>
instead of
2004-08-10 09:56:55 +00:00
<blockquote>
2004-08-12 10:58:13 +00:00
<pre><span class=keyword>using </span><span class=keyword>namespace </span><span class=identifier>boost</span><span class=special>;</span>
<span class=identifier>begin</span><span class=special>( </span><span class=identifier>r </span><span class=special>)</span></pre></blockquote>
when calling functions in this library? If so, can I still rely on argument
2004-08-10 09:56:55 +00:00
dependent lookup (ADL) to kick in?</i>
<p>
The answer to the first question is that "it's up to you". The
answer to the second question is Yes. Normally qualified syntax
disables ADL, but the functions are implemented in a special
manner that preserves ADL properties. The trick was explained by
Daniel Frey on comp.lang.std.c++ in the thread "Whence Swap" and
2004-08-10 09:56:55 +00:00
it is best explained by some code: <blockquote>
<pre>
2004-08-12 10:58:13 +00:00
<span class=keyword>namespace </span><span class=identifier>boost</span>
<span class=special>{
</span><span class=keyword>namespace </span><span class=identifier>range_detail
2004-08-12 10:58:13 +00:00
</span><span class=special>{
</span><span class=keyword>template</span><span class=special>&lt; </span><span class=keyword>class </span><span class=identifier>T </span><span class=special>&gt;
2004-08-16 22:47:16 +00:00
</span><span class=keyword>typename </span><span class=identifier>range_iterator</span><span class=special>&lt;</span><span class=identifier>T</span><span class=special>&gt;:</span><span class=identifier>type </span><span class=identifier>begin</span><span class=special>( </span><span class=identifier>T</span><span class=special>&amp; </span><span class=identifier>r </span><span class=special>)
2004-08-12 10:58:13 +00:00
</span><span class=special>{ </span><span class=comment>/* normal implementation */ </span><span class=special>}
</span><span class=special>}
</span><span class=keyword>template</span><span class=special>&lt; </span><span class=keyword>class </span><span class=identifier>T </span><span class=special>&gt;
2004-08-16 22:47:16 +00:00
</span><span class=keyword>typename </span><span class=identifier>range_iterator</span><span class=special>&lt;</span><span class=identifier>T</span><span class=special>&gt;::</span><span class=identifier>type </span><span class=identifier>begin</span><span class=special>( </span><span class=identifier>T</span><span class=special>&amp; </span><span class=identifier>r </span><span class=special>)
2004-08-12 10:58:13 +00:00
</span><span class=special>{
</span><span class=comment>//
2004-08-10 09:56:55 +00:00
// Create ADL hook
//
</span><span class=keyword>using </span><span class=identifier>range_detail</span><span class=special>::</span><span class=identifier>begin</span><span class=special>;
</span><span class=keyword>return </span><span class=identifier>begin</span><span class=special>( </span><span class=identifier>r </span><span class=special>);
2004-08-12 10:58:13 +00:00
</span><span class=special>}</span>
<span class=special>} </span>
2004-08-12 10:58:13 +00:00
</pre>
</blockquote>
Cool indeed!
2004-08-10 09:56:55 +00:00
</p>
-->
2004-08-10 09:56:55 +00:00
2004-08-05 19:37:40 +00:00
</ol>
<hr>
<p>
(C) Copyright Thorsten Ottosen 2003-2004
2004-08-05 19:37:40 +00:00
</p>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
</body>
</html>