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="cboost.gif" border="0" ></td>
|
|
|
|
<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 >
|
2004-08-10 09:56:55 +00:00
|
|
|
<i>Why is there no difference between <code >iterator_of<C>::type</code>
|
|
|
|
and <code >const_iterator_of<C>::type</code> for <code >std::pair<iterator,
|
|
|
|
iterator></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<const_iterator,const_iterator></code>
|
|
|
|
object.
|
|
|
|
</p>
|
|
|
|
<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 >
|
2004-08-10 09:56:55 +00:00
|
|
|
The library have been kept small because its current interface will serve most
|
|
|
|
purposes. If and when a genuine need arises for more functionality, it can be
|
|
|
|
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 >
|
2004-08-10 09:56:55 +00:00
|
|
|
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
|
|
|
|
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.
|
|
|
|
</p>
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<i>Should I use qualified syntax, for example
|
|
|
|
<blockquote><pre>boost::begin( r ); </pre></blockquote>
|
|
|
|
instead of
|
|
|
|
<blockquote>
|
|
|
|
<pre>using namespace boost;
|
|
|
|
begin( r )</pre></blockquote>
|
|
|
|
when calling functions in this library? If so, can I still rely on argument
|
|
|
|
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
|
|
|
|
it is best explained by some code: <blockquote>
|
|
|
|
<pre>
|
|
|
|
namespace boost
|
|
|
|
{
|
|
|
|
namespace range_detail
|
|
|
|
{
|
|
|
|
template< class T >
|
|
|
|
typename iterator_of<T>:type begin( T& r )
|
|
|
|
{ /* normal implementation */ }
|
|
|
|
}
|
|
|
|
|
|
|
|
template< class T >
|
|
|
|
typename iterator_of<T>::type begin( T& r )
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Create ADL hook
|
|
|
|
//
|
|
|
|
using range_detail::begin;
|
|
|
|
return begin( r );
|
|
|
|
}
|
|
|
|
} </pre>
|
|
|
|
</blockquote>
|
|
|
|
</p>
|
|
|
|
|
2004-08-05 19:37:40 +00:00
|
|
|
</ol>
|
|
|
|
|
|
|
|
|
|
|
|
<hr>
|
|
|
|
<p>
|
|
|
|
(C) Copyright Thorsten Ottosen 2003-2004
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<br>
|
|
|
|
<br>
|
|
|
|
<br>
|
|
|
|
<br>
|
|
|
|
<br>
|
|
|
|
<br>
|
|
|
|
<br>
|
|
|
|
<br>
|
|
|
|
<br>
|
|
|
|
<br>
|
|
|
|
<br>
|
|
|
|
<br>
|
|
|
|
|
|
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
|