| 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 FAQ </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 | <p> |
|---|
| 20 | <h2 >FAQ</h2> <a name="FAQ" ></a> |
|---|
| 21 | <ol > |
|---|
| 22 | <li > |
|---|
| 23 | <i>Why is there no difference between <code >range_iterator<C>::type</code> |
|---|
| 24 | and <code >range_const_iterator<C>::type</code> for <code>std::pair<iterator, iterator></code></i>. |
|---|
| 25 | </li> |
|---|
| 26 | <p > |
|---|
| 27 | In general it is not possible nor desirable to find a corresponding <code >const_iterator</code>. |
|---|
| 28 | When it is possible to come up with one, the client might choose to construct a <code >std::pair<const_iterator,const_iterator></code> |
|---|
| 29 | object. |
|---|
| 30 | </p> |
|---|
| 31 | <p> |
|---|
| 32 | Note that an <a href="utility_class.html#iter_range">iterator_range</a> |
|---|
| 33 | is somewhat more convenient than a <code>pair</code> and that a <a |
|---|
| 34 | href="utility_class.html#sub_range"><code>sub_range</code></a> does |
|---|
| 35 | propagate const-ness. </p> |
|---|
| 36 | |
|---|
| 37 | <li > |
|---|
| 38 | <i>Why is there not supplied more types or more functions?</i> |
|---|
| 39 | <p > |
|---|
| 40 | The library has been kept small because its current interface will |
|---|
| 41 | serve most |
|---|
| 42 | purposes. If and when a genuine need arises for more functionality, it can be |
|---|
| 43 | implemented. |
|---|
| 44 | </p> |
|---|
| 45 | </li> |
|---|
| 46 | <li > |
|---|
| 47 | <i>How should I implement generic algorithms for ranges?</i> |
|---|
| 48 | <p > |
|---|
| 49 | One should always start with a generic algorithm that takes two iterators (or |
|---|
| 50 | more) as input. Then use Boost.Range to build handier versions on top of the |
|---|
| 51 | iterator based algorithm. Please notice that once the range version of the |
|---|
| 52 | algorithm is done, it makes sense <i>not</i> to expose the iterator version in |
|---|
| 53 | the public interface. |
|---|
| 54 | </p> |
|---|
| 55 | </li> |
|---|
| 56 | <li> |
|---|
| 57 | <i>Why is there no Incrementable Range concept?</i> |
|---|
| 58 | <p> |
|---|
| 59 | Even though we speak of incrementable iterators, it would not make |
|---|
| 60 | much sense for ranges; for example, we cannot determine the size and |
|---|
| 61 | emptiness of a range since we cannot even compare |
|---|
| 62 | its iterators. |
|---|
| 63 | </p> |
|---|
| 64 | <p> |
|---|
| 65 | Note also that incrementable iterators are derived from output |
|---|
| 66 | iterators and so there exist no output range. |
|---|
| 67 | </p> |
|---|
| 68 | </li> |
|---|
| 69 | <!-- |
|---|
| 70 | <li> |
|---|
| 71 | <i>Should I use qualified syntax, for example |
|---|
| 72 | <blockquote><pre> |
|---|
| 73 | <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> |
|---|
| 74 | </pre></blockquote> |
|---|
| 75 | instead of |
|---|
| 76 | <blockquote> |
|---|
| 77 | <pre><span class=keyword>using </span><span class=keyword>namespace </span><span class=identifier>boost</span><span class=special>;</span> |
|---|
| 78 | <span class=identifier>begin</span><span class=special>( </span><span class=identifier>r </span><span class=special>)</span></pre></blockquote> |
|---|
| 79 | when calling functions in this library? If so, can I still rely on argument |
|---|
| 80 | dependent lookup (ADL) to kick in?</i> |
|---|
| 81 | <p> |
|---|
| 82 | The answer to the first question is that "it's up to you". The |
|---|
| 83 | answer to the second question is Yes. Normally qualified syntax |
|---|
| 84 | disables ADL, but the functions are implemented in a special |
|---|
| 85 | manner that preserves ADL properties. The trick was explained by |
|---|
| 86 | Daniel Frey on comp.lang.std.c++ in the thread "Whence Swap" and |
|---|
| 87 | it is best explained by some code: <blockquote> |
|---|
| 88 | <pre> |
|---|
| 89 | <span class=keyword>namespace </span><span class=identifier>boost</span> |
|---|
| 90 | <span class=special>{ |
|---|
| 91 | </span><span class=keyword>namespace </span><span class=identifier>range_detail |
|---|
| 92 | </span><span class=special>{ |
|---|
| 93 | </span><span class=keyword>template</span><span class=special>< </span><span class=keyword>class </span><span class=identifier>T </span><span class=special>> |
|---|
| 94 | </span><span class=keyword>typename </span><span class=identifier>range_iterator</span><span class=special><</span><span class=identifier>T</span><span class=special>>:</span><span class=identifier>type </span><span class=identifier>begin</span><span class=special>( </span><span class=identifier>T</span><span class=special>& </span><span class=identifier>r </span><span class=special>) |
|---|
| 95 | </span><span class=special>{ </span><span class=comment>/* normal implementation */ </span><span class=special>} |
|---|
| 96 | </span><span class=special>} |
|---|
| 97 | |
|---|
| 98 | </span><span class=keyword>template</span><span class=special>< </span><span class=keyword>class </span><span class=identifier>T </span><span class=special>> |
|---|
| 99 | </span><span class=keyword>typename </span><span class=identifier>range_iterator</span><span class=special><</span><span class=identifier>T</span><span class=special>>::</span><span class=identifier>type </span><span class=identifier>begin</span><span class=special>( </span><span class=identifier>T</span><span class=special>& </span><span class=identifier>r </span><span class=special>) |
|---|
| 100 | </span><span class=special>{ |
|---|
| 101 | </span><span class=comment>// |
|---|
| 102 | // Create ADL hook |
|---|
| 103 | // |
|---|
| 104 | </span><span class=keyword>using </span><span class=identifier>range_detail</span><span class=special>::</span><span class=identifier>begin</span><span class=special>; |
|---|
| 105 | </span><span class=keyword>return </span><span class=identifier>begin</span><span class=special>( </span><span class=identifier>r </span><span class=special>); |
|---|
| 106 | </span><span class=special>}</span> |
|---|
| 107 | <span class=special>} </span> |
|---|
| 108 | </pre> |
|---|
| 109 | </blockquote> |
|---|
| 110 | Cool indeed! |
|---|
| 111 | </p> |
|---|
| 112 | --> |
|---|
| 113 | |
|---|
| 114 | </ol> |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | <hr> |
|---|
| 118 | <p> |
|---|
| 119 | (C) Copyright Thorsten Ottosen 2003-2004 |
|---|
| 120 | </p> |
|---|
| 121 | |
|---|
| 122 | <br> |
|---|
| 123 | <br> |
|---|
| 124 | <br> |
|---|
| 125 | <br> |
|---|
| 126 | <br> |
|---|
| 127 | <br> |
|---|
| 128 | <br> |
|---|
| 129 | <br> |
|---|
| 130 | <br> |
|---|
| 131 | <br> |
|---|
| 132 | <br> |
|---|
| 133 | <br> |
|---|
| 134 | |
|---|
| 135 | |
|---|
| 136 | </body> |
|---|
| 137 | </html> |
|---|
| 138 | |
|---|