range.html 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=us-ascii" />
  6. <link rel="stylesheet" href="../../../../boost.css" type="text/css"/>
  7. <link rel="stylesheet" href="ublas.css" type="text/css" />
  8. <script type="text/javascript" src="js/jquery-1.3.2.min.js" async="async" ></script>
  9. <script type="text/javascript" src="js/jquery.toc-gw.js" async="async" ></script>
  10. <title>Range and slice</title>
  11. </head>
  12. <body>
  13. <h1><img src="../../../../boost.png" align="middle" />Range and Slice Storage</h1>
  14. <div class="toc" id="toc"></div>
  15. <h2><a name="range"></a>Range&lt;SizeType,DistanceType&gt;</h2>
  16. <h4>Description</h4>
  17. <p>The class <code>range</code> specifies a range of indicies. The range is a sequence of indices
  18. from a start value to stop value. The indices increase by one and exlude the stop value.
  19. <code>range</code> can therefore be used to specify ranges of elements from vectors and matrices.</p>
  20. <h4>Example</h4>
  21. <pre>
  22. #include &lt;boost/numeric/ublas/storage.hpp&gt;
  23. int main () {
  24. using namespace boost::numeric::ublas;
  25. range r (0, 3);
  26. for (unsigned i = 0; i &lt; r.size (); ++ i) {
  27. std::cout &lt;&lt; r (i) &lt;&lt; std::endl;
  28. }
  29. }
  30. </pre>
  31. <h4>Definition</h4>
  32. <p>Defined in the header storage.hpp.</p>
  33. <h4>Model of</h4>
  34. <p>Reversible Container.</p>
  35. <h4>Type requirements</h4>
  36. <p>None, except for those imposed by the requirements of Reversible
  37. Container.</p>
  38. <h4>Public base classes</h4>
  39. <p>None.</p>
  40. <h4>Members</h4>
  41. <table border="1" summary="members">
  42. <tbody>
  43. <tr>
  44. <th>Member</th>
  45. <th>Description</th>
  46. </tr>
  47. <tr>
  48. <td><code>range (size_type start, size_type stop)</code></td>
  49. <td>Constructs a range of indicies from <code>start</code> to <code>stop (excluded)</code>
  50. .</td>
  51. </tr>
  52. <tr>
  53. <td><code>size_type start () const</code></td>
  54. <td>Returns the beginning of the <code>range</code>.</td>
  55. </tr>
  56. <tr>
  57. <td><code>size_type size () const</code></td>
  58. <td>Returns the size of the <code>range</code>.</td>
  59. </tr>
  60. <tr>
  61. <td><code>const_reference operator [] (size_type i)
  62. const</code></td>
  63. <td>Returns the value <code>start + i</code> of the <code>i</code>
  64. -th element.</td>
  65. </tr>
  66. <tr>
  67. <td><code>range compose (const range &amp;r) const</code></td>
  68. <td>Returns the composite range from <code>start + r.start
  69. ()</code> to <code>start + r.start () + r.size ()</code>.</td>
  70. </tr>
  71. <tr>
  72. <td><code>bool operator == (const range &amp;r) const</code></td>
  73. <td>Tests two ranges for equality.</td>
  74. </tr>
  75. <tr>
  76. <td><code>bool operator != (const range &amp;r) const</code></td>
  77. <td>Tests two ranges for inequality.</td>
  78. </tr>
  79. <tr>
  80. <td><code>const_iterator begin () const</code></td>
  81. <td>Returns a <code>const_iterator</code> pointing to the beginning
  82. of the <code>range</code>.</td>
  83. </tr>
  84. <tr>
  85. <td><code>const_iterator end () const</code></td>
  86. <td>Returns a <code>const_iterator</code> pointing to the end of
  87. the <code>range</code>.</td>
  88. </tr>
  89. <tr>
  90. <td><code>const_reverse_iterator rbegin () const</code></td>
  91. <td>Returns a <code>const_reverse_iterator</code> pointing to the
  92. beginning of the reversed <code>range</code>.</td>
  93. </tr>
  94. <tr>
  95. <td><code>const_reverse_iterator rend () const</code></td>
  96. <td>Returns a <code>const_reverse_iterator</code> pointing to the
  97. end of the reversed <code>range</code>.</td>
  98. </tr>
  99. </tbody>
  100. </table>
  101. <h4>Preconditions</h4>
  102. <ul>
  103. <li><code>start () &lt;= stop ()</code></li>
  104. </ul>
  105. <h2><a name="slice"></a>Slice&lt;SizeType,DistanceType&gt;</h2>
  106. <h4>Description</h4>
  107. <p>The class <code>slice</code> specifies a 'slice' of indicies. Slices are more general
  108. then ranges, the stride allows the sequence of indicies to increase and decrease by the specified amount between element.
  109. <code>slice</code> can therefore be used to specify slices of element from vectors and matrices.</p>
  110. <h4>Example</h4>
  111. <pre>
  112. #include &lt;boost/numeric/ublas/storage.hpp&gt;
  113. int main () {
  114. using namespace boost::numeric::ublas;
  115. slice s (0, 1, 3);
  116. for (unsigned i = 0; i &lt; s.size (); ++ i) {
  117. std::cout &lt;&lt; s (i) &lt;&lt; std::endl;
  118. }
  119. }
  120. </pre>
  121. <h4>Definition</h4>
  122. <p>Defined in the header storage.hpp.</p>
  123. <h4>Model of</h4>
  124. <p>Reversible Container.</p>
  125. <h4>Type requirements</h4>
  126. <p>None, except for those imposed by the requirements of Reversible
  127. Container.</p>
  128. <h4>Public base classes</h4>
  129. <p>None.</p>
  130. <h4>Members</h4>
  131. <table border="1" summary="members">
  132. <tbody>
  133. <tr>
  134. <th>Member</th>
  135. <th>Description</th>
  136. </tr>
  137. <tr>
  138. <td><code>slice (size_type start, size_type stride, size_type
  139. size)</code></td>
  140. <td>Constructs a slice <code>start,start+stride,start+2*stride...</code> with
  141. <code>size</code> elements.</td>
  142. </tr>
  143. <tr>
  144. <td><code>size_type start () const</code></td>
  145. <td>Returns the beginning of the <code>slice</code>.</td>
  146. </tr>
  147. <tr>
  148. <td><code>size_type stride () const</code></td>
  149. <td>Returns the stride of the <code>slice</code>.</td>
  150. </tr>
  151. <tr>
  152. <td><code>size_type size () const</code></td>
  153. <td>Returns the size of the <code>slice</code>.</td>
  154. </tr>
  155. <tr>
  156. <td><code>const_reference operator [] (size_type i)
  157. const</code></td>
  158. <td>Returns the value <code>start + i * stride</code> of the
  159. <code>i</code>-th element.</td>
  160. </tr>
  161. <tr>
  162. <td><code>slice compose (const range &amp;r) const</code></td>
  163. <td>Returns the composite slice from <code>start + stride * r.start
  164. ()</code> to <code>start + stride * (r.start () + r.size ())</code>
  165. with stride <code>stride</code>.</td>
  166. </tr>
  167. <tr>
  168. <td><code>slice compose (const slice &amp;s) const</code></td>
  169. <td>Returns the composite slice from <code>start + stride * s.start
  170. ()</code> to <code>start + stride * s.stride () * (s.start () +
  171. s.size ())</code> with stride <code>stride * s.stride ()</code>
  172. .</td>
  173. </tr>
  174. <tr>
  175. <td><code>bool operator == (const slice &amp;s) const</code></td>
  176. <td>Tests two slices for equality.</td>
  177. </tr>
  178. <tr>
  179. <td><code>bool operator != (const slice &amp;s) const</code></td>
  180. <td>Tests two slices for inequality.</td>
  181. </tr>
  182. <tr>
  183. <td><code>const_iterator begin () const</code></td>
  184. <td>Returns a <code>const_iterator</code> pointing to the beginning
  185. of the <code>slice</code>.</td>
  186. </tr>
  187. <tr>
  188. <td><code>const_iterator end () const</code></td>
  189. <td>Returns a <code>const_iterator</code> pointing to the end of
  190. the <code>slice</code>.</td>
  191. </tr>
  192. <tr>
  193. <td><code>const_reverse_iterator rbegin () const</code></td>
  194. <td>Returns a <code>const_reverse_iterator</code> pointing to the
  195. beginning of the reversed <code>slice</code>.</td>
  196. </tr>
  197. <tr>
  198. <td><code>const_reverse_iterator rend () const</code></td>
  199. <td>Returns a <code>const_reverse_iterator</code> pointing to the
  200. end of the reversed <code>slice</code>.</td>
  201. </tr>
  202. </tbody>
  203. </table>
  204. <h4>Preconditions</h4>
  205. <ul>
  206. <li>None all strides are vaild. However when an index is returned or an iterator is dereferenced its
  207. value must be representable as the size_type.</li>
  208. </ul>
  209. <hr/>
  210. <p>
  211. Copyright (&copy;) 2000-2004 Michael Stevens, Mathias Koch,
  212. Joerg Walter, Gunter Winkler<br />
  213. Use, modification and distribution are subject to the
  214. Boost Software License, Version 1.0.
  215. (See accompanying file LICENSE_1_0.txt
  216. or copy at <a href="http://www.boost.org/LICENSE_1_0.txt">
  217. http://www.boost.org/LICENSE_1_0.txt
  218. </a>).
  219. </p>
  220. <script type="text/javascript">
  221. (function($) {
  222. $('#toc').toc();
  223. })(jQuery);
  224. </script>
  225. </body>
  226. </html>