[12] | 1 | <HTML> |
---|
| 2 | <!-- |
---|
| 3 | -- Copyright (c) Jeremy Siek 2000 |
---|
| 4 | -- |
---|
| 5 | -- Permission to use, copy, modify, distribute and sell this software |
---|
| 6 | -- and its documentation for any purpose is hereby granted without fee, |
---|
| 7 | -- provided that the above copyright notice appears in all copies and |
---|
| 8 | -- that both that copyright notice and this permission notice appear |
---|
| 9 | -- in supporting documentation. Silicon Graphics makes no |
---|
| 10 | -- representations about the suitability of this software for any |
---|
| 11 | -- purpose. It is provided "as is" without express or implied warranty. |
---|
| 12 | --> |
---|
| 13 | <Head> |
---|
| 14 | <Title>Collection</Title> |
---|
| 15 | </HEAD> |
---|
| 16 | |
---|
| 17 | <BODY BGCOLOR="#ffffff" LINK="#0000ee" TEXT="#000000" VLINK="#551a8b" |
---|
| 18 | ALINK="#ff0000"> |
---|
| 19 | <h1> |
---|
| 20 | <img src="../../boost.png" alt="boost logo" |
---|
| 21 | width="277" align="middle" height="86"> |
---|
| 22 | <br>Collection |
---|
| 23 | </h1> |
---|
| 24 | |
---|
| 25 | <h3>Description</h3> |
---|
| 26 | |
---|
| 27 | A Collection is a <i>concept</i> similar to the STL <a |
---|
| 28 | href="http://www.sgi.com/tech/stl/Container.html">Container</a> |
---|
| 29 | concept. A Collection provides iterators for accessing a range of |
---|
| 30 | elements and provides information about the number of elements in the |
---|
| 31 | Collection. However, a Collection has fewer requirements than a |
---|
| 32 | Container. The motivation for the Collection concept is that there are |
---|
| 33 | many useful Container-like types that do not meet the full |
---|
| 34 | requirements of Container, and many algorithms that can be written |
---|
| 35 | with this reduced set of requirements. To summarize the reduction |
---|
| 36 | in requirements: |
---|
| 37 | |
---|
| 38 | <UL> |
---|
| 39 | <LI>It is not required to "own" its elements: the lifetime |
---|
| 40 | of an element in a Collection does not have to match the lifetime of |
---|
| 41 | the Collection object, though the lifetime of the element should cover |
---|
| 42 | the lifetime of the Collection object. |
---|
| 43 | <LI>The semantics of copying a Collection object is not defined (it |
---|
| 44 | could be a deep or shallow copy or not even support copying). |
---|
| 45 | <LI>The associated reference type of a Collection does |
---|
| 46 | not have to be a real C++ reference. |
---|
| 47 | </UL> |
---|
| 48 | |
---|
| 49 | |
---|
| 50 | Because of the reduced requirements, some care must be taken when |
---|
| 51 | writing code that is meant to be generic for all Collection types. |
---|
| 52 | In particular, a Collection object should be passed by-reference |
---|
| 53 | since assumptions can not be made about the behaviour of the |
---|
| 54 | copy constructor. |
---|
| 55 | |
---|
| 56 | <p> |
---|
| 57 | |
---|
| 58 | <h3>Associated types</h3> |
---|
| 59 | |
---|
| 60 | <Table border> |
---|
| 61 | <TR> |
---|
| 62 | <TD VAlign=top> |
---|
| 63 | Value type |
---|
| 64 | </TD> |
---|
| 65 | <TD VAlign=top> |
---|
| 66 | <tt>X::value_type</tt> |
---|
| 67 | </TD> |
---|
| 68 | <TD VAlign=top> |
---|
| 69 | The type of the object stored in a Collection. |
---|
| 70 | If the Collection is <i>mutable</i> then |
---|
| 71 | the value type must be <A |
---|
| 72 | href="http://www.sgi.com/tech/stl/Assignable.html">Assignable</A>. |
---|
| 73 | Otherwise the value type must be <a href="./CopyConstructible.html">CopyConstructible</a>. |
---|
| 74 | </TD> |
---|
| 75 | </TR> |
---|
| 76 | <TR> |
---|
| 77 | <TD VAlign=top> |
---|
| 78 | Iterator type |
---|
| 79 | </TD> |
---|
| 80 | <TD VAlign=top> |
---|
| 81 | <tt>X::iterator</tt> |
---|
| 82 | </TD> |
---|
| 83 | <TD VAlign=top> |
---|
| 84 | The type of iterator used to iterate through a Collection's |
---|
| 85 | elements. The iterator's value type is expected to be the |
---|
| 86 | Collection's value type. A conversion |
---|
| 87 | from the iterator type to the const iterator type must exist. |
---|
| 88 | The iterator type must be an <A href="http://www.sgi.com/tech/stl/InputIterator.html">InputIterator</A>. |
---|
| 89 | </TD> |
---|
| 90 | </TR> |
---|
| 91 | <TR> |
---|
| 92 | <TD VAlign=top> |
---|
| 93 | Const iterator type |
---|
| 94 | </TD> |
---|
| 95 | <TD VAlign=top> |
---|
| 96 | <tt>X::const_iterator</tt> |
---|
| 97 | </TD> |
---|
| 98 | <TD VAlign=top> |
---|
| 99 | A type of iterator that may be used to examine, but not to modify, |
---|
| 100 | a Collection's elements. |
---|
| 101 | </TD> |
---|
| 102 | </TR> |
---|
| 103 | <TR> |
---|
| 104 | <TD VAlign=top> |
---|
| 105 | Reference type |
---|
| 106 | </TD> |
---|
| 107 | <TD VAlign=top> |
---|
| 108 | <tt>X::reference</tt> |
---|
| 109 | </TD> |
---|
| 110 | <TD VAlign=top> |
---|
| 111 | A type that behaves like a reference to the Collection's value type. |
---|
| 112 | <a href="#1">[1]</a> |
---|
| 113 | </TD> |
---|
| 114 | </TR> |
---|
| 115 | <TR> |
---|
| 116 | <TD VAlign=top> |
---|
| 117 | Const reference type |
---|
| 118 | </TD> |
---|
| 119 | <TD VAlign=top> |
---|
| 120 | <tt>X::const_reference</tt> |
---|
| 121 | </TD> |
---|
| 122 | <TD VAlign=top> |
---|
| 123 | A type that behaves like a const reference to the Collection's value type. |
---|
| 124 | </TD> |
---|
| 125 | </TR> |
---|
| 126 | <TR> |
---|
| 127 | <TD VAlign=top> |
---|
| 128 | Pointer type |
---|
| 129 | </TD> |
---|
| 130 | <TD VAlign=top> |
---|
| 131 | <tt>X::pointer</tt> |
---|
| 132 | </TD> |
---|
| 133 | <TD VAlign=top> |
---|
| 134 | A type that behaves as a pointer to the Collection's value type. |
---|
| 135 | </TD> |
---|
| 136 | </TR> |
---|
| 137 | <TR> |
---|
| 138 | <TD VAlign=top> |
---|
| 139 | Distance type |
---|
| 140 | </TD> |
---|
| 141 | <TD VAlign=top> |
---|
| 142 | <tt>X::difference_type</tt> |
---|
| 143 | </TD> |
---|
| 144 | <TD VAlign=top> |
---|
| 145 | A signed integral type used to represent the distance between two |
---|
| 146 | of the Collection's iterators. This type must be the same as |
---|
| 147 | the iterator's distance type. |
---|
| 148 | </TD> |
---|
| 149 | </TR> |
---|
| 150 | <TR> |
---|
| 151 | <TD VAlign=top> |
---|
| 152 | Size type |
---|
| 153 | </TD> |
---|
| 154 | <TD VAlign=top> |
---|
| 155 | <tt>X::size_type</tt> |
---|
| 156 | </TD> |
---|
| 157 | <TD VAlign=top> |
---|
| 158 | An unsigned integral type that can represent any nonnegative value |
---|
| 159 | of the Collection's distance type. |
---|
| 160 | </TD> |
---|
| 161 | </tr> |
---|
| 162 | </table> |
---|
| 163 | <h3>Notation</h3> |
---|
| 164 | <Table> |
---|
| 165 | <TR> |
---|
| 166 | <TD VAlign=top> |
---|
| 167 | <tt>X</tt> |
---|
| 168 | </TD> |
---|
| 169 | <TD VAlign=top> |
---|
| 170 | A type that is a model of Collection. |
---|
| 171 | </TD> |
---|
| 172 | </TR> |
---|
| 173 | <TR> |
---|
| 174 | <TD VAlign=top> |
---|
| 175 | <tt>a</tt>, <tt>b</tt> |
---|
| 176 | </TD> |
---|
| 177 | <TD VAlign=top> |
---|
| 178 | Object of type <tt>X</tt>. |
---|
| 179 | </TD> |
---|
| 180 | </TR> |
---|
| 181 | <TR> |
---|
| 182 | <TD VAlign=top> |
---|
| 183 | <tt>T</tt> |
---|
| 184 | </TD> |
---|
| 185 | <TD VAlign=top> |
---|
| 186 | The value type of <tt>X</tt>. |
---|
| 187 | </TD> |
---|
| 188 | </tr> |
---|
| 189 | </table> |
---|
| 190 | |
---|
| 191 | <h3>Valid expressions</h3> |
---|
| 192 | |
---|
| 193 | The following expressions must be valid. |
---|
| 194 | <p> |
---|
| 195 | |
---|
| 196 | <Table border> |
---|
| 197 | <TR> |
---|
| 198 | <TH> |
---|
| 199 | Name |
---|
| 200 | </TH> |
---|
| 201 | <TH> |
---|
| 202 | Expression |
---|
| 203 | </TH> |
---|
| 204 | <TH> |
---|
| 205 | Return type |
---|
| 206 | </TH> |
---|
| 207 | </TR> |
---|
| 208 | <TR> |
---|
| 209 | <TD VAlign=top> |
---|
| 210 | Beginning of range |
---|
| 211 | </TD> |
---|
| 212 | <TD VAlign=top> |
---|
| 213 | <tt>a.begin()</tt> |
---|
| 214 | </TD> |
---|
| 215 | <TD VAlign=top> |
---|
| 216 | <tt>iterator</tt> if <tt>a</tt> is mutable, <tt>const_iterator</tt> otherwise |
---|
| 217 | </TD> |
---|
| 218 | </TR> |
---|
| 219 | <TR> |
---|
| 220 | <TD VAlign=top> |
---|
| 221 | End of range |
---|
| 222 | </TD> |
---|
| 223 | <TD VAlign=top> |
---|
| 224 | <tt>a.end()</tt> |
---|
| 225 | </TD> |
---|
| 226 | <TD VAlign=top> |
---|
| 227 | <tt>iterator</tt> if <tt>a</tt> is mutable, <tt>const_iterator</tt> otherwise |
---|
| 228 | </TD> |
---|
| 229 | </TR> |
---|
| 230 | <TR> |
---|
| 231 | <TD VAlign=top> |
---|
| 232 | Size |
---|
| 233 | </TD> |
---|
| 234 | <TD VAlign=top> |
---|
| 235 | <tt>a.size()</tt> |
---|
| 236 | </TD> |
---|
| 237 | <TD VAlign=top> |
---|
| 238 | <tt>size_type</tt> |
---|
| 239 | </TD> |
---|
| 240 | </TR> |
---|
| 241 | <!-- |
---|
| 242 | <TR> |
---|
| 243 | <TD VAlign=top> |
---|
| 244 | Maximum size |
---|
| 245 | </TD> |
---|
| 246 | <TD VAlign=top> |
---|
| 247 | <tt>a.max_size()</tt> |
---|
| 248 | </TD> |
---|
| 249 | <TD VAlign=top> |
---|
| 250 | <tt>size_type</tt> |
---|
| 251 | </TD> |
---|
| 252 | </TR> |
---|
| 253 | <TR> |
---|
| 254 | --> |
---|
| 255 | <TD VAlign=top> |
---|
| 256 | Empty Collection |
---|
| 257 | </TD> |
---|
| 258 | <TD VAlign=top> |
---|
| 259 | <tt>a.empty()</tt> |
---|
| 260 | </TD> |
---|
| 261 | <TD VAlign=top> |
---|
| 262 | Convertible to <tt>bool</tt> |
---|
| 263 | </TD> |
---|
| 264 | </TR> |
---|
| 265 | <TR> |
---|
| 266 | <TD VAlign=top> |
---|
| 267 | Swap |
---|
| 268 | </TD> |
---|
| 269 | <TD VAlign=top> |
---|
| 270 | <tt>a.swap(b)</tt> |
---|
| 271 | </TD> |
---|
| 272 | <TD VAlign=top> |
---|
| 273 | <tt>void</tt> |
---|
| 274 | </TD> |
---|
| 275 | </tr> |
---|
| 276 | </table> |
---|
| 277 | <h3>Expression semantics</h3> |
---|
| 278 | |
---|
| 279 | <Table border> |
---|
| 280 | <TR> |
---|
| 281 | <TH> |
---|
| 282 | Name |
---|
| 283 | </TH> |
---|
| 284 | <TH> |
---|
| 285 | Expression |
---|
| 286 | </TH> |
---|
| 287 | <TH> |
---|
| 288 | Semantics |
---|
| 289 | </TH> |
---|
| 290 | <TH> |
---|
| 291 | Postcondition |
---|
| 292 | </TH> |
---|
| 293 | </TR> |
---|
| 294 | <TD VAlign=top> |
---|
| 295 | <TR> |
---|
| 296 | <TD VAlign=top> |
---|
| 297 | Beginning of range |
---|
| 298 | </TD> |
---|
| 299 | <TD VAlign=top> |
---|
| 300 | <tt>a.begin()</tt> |
---|
| 301 | </TD> |
---|
| 302 | <TD VAlign=top> |
---|
| 303 | Returns an iterator pointing to the first element in the Collection. |
---|
| 304 | </TD> |
---|
| 305 | <TD VAlign=top> |
---|
| 306 | <tt>a.begin()</tt> is either dereferenceable or past-the-end. It is |
---|
| 307 | past-the-end if and only if <tt>a.size() == 0</tt>. |
---|
| 308 | </TD> |
---|
| 309 | </TR> |
---|
| 310 | <TR> |
---|
| 311 | <TD VAlign=top> |
---|
| 312 | End of range |
---|
| 313 | </TD> |
---|
| 314 | <TD VAlign=top> |
---|
| 315 | <tt>a.end()</tt> |
---|
| 316 | </TD> |
---|
| 317 | <TD VAlign=top> |
---|
| 318 | Returns an iterator pointing one past the last element in the |
---|
| 319 | Collection. |
---|
| 320 | </TD> |
---|
| 321 | <TD VAlign=top> |
---|
| 322 | <tt>a.end()</tt> is past-the-end. |
---|
| 323 | </TD> |
---|
| 324 | </TR> |
---|
| 325 | <TR> |
---|
| 326 | <TD VAlign=top> |
---|
| 327 | Size |
---|
| 328 | </TD> |
---|
| 329 | <TD VAlign=top> |
---|
| 330 | <tt>a.size()</tt> |
---|
| 331 | </TD> |
---|
| 332 | <TD VAlign=top> |
---|
| 333 | Returns the size of the Collection, that is, its number of elements. |
---|
| 334 | </TD> |
---|
| 335 | <TD VAlign=top> |
---|
| 336 | <tt>a.size() >= 0 |
---|
| 337 | </TD> |
---|
| 338 | </TR> |
---|
| 339 | <!-- |
---|
| 340 | <TR> |
---|
| 341 | <TD VAlign=top> |
---|
| 342 | Maximum size |
---|
| 343 | </TD> |
---|
| 344 | <TD VAlign=top> |
---|
| 345 | <tt>a.max_size()</tt> |
---|
| 346 | </TD> |
---|
| 347 | <TD VAlign=top> |
---|
| 348 | |
---|
| 349 | </TD> |
---|
| 350 | <TD VAlign=top> |
---|
| 351 | Returns the largest size that this Collection can ever have. <A href="#8">[8]</A> |
---|
| 352 | </TD> |
---|
| 353 | <TD VAlign=top> |
---|
| 354 | <tt>a.max_size() >= 0 && a.max_size() >= a.size()</tt> |
---|
| 355 | </TD> |
---|
| 356 | </TR> |
---|
| 357 | --> |
---|
| 358 | <TR> |
---|
| 359 | <TD VAlign=top> |
---|
| 360 | Empty Collection |
---|
| 361 | </TD> |
---|
| 362 | <TD VAlign=top> |
---|
| 363 | <tt>a.empty()</tt> |
---|
| 364 | </TD> |
---|
| 365 | <TD VAlign=top> |
---|
| 366 | Equivalent to <tt>a.size() == 0</tt>. (But possibly faster.) |
---|
| 367 | </TD> |
---|
| 368 | <TD VAlign=top> |
---|
| 369 | |
---|
| 370 | </TD> |
---|
| 371 | </TR> |
---|
| 372 | <TR> |
---|
| 373 | <TD VAlign=top> |
---|
| 374 | Swap |
---|
| 375 | </TD> |
---|
| 376 | <TD VAlign=top> |
---|
| 377 | <tt>a.swap(b)</tt> |
---|
| 378 | </TD> |
---|
| 379 | <TD VAlign=top> |
---|
| 380 | Equivalent to <tt>swap(a,b)</tt> |
---|
| 381 | </TD> |
---|
| 382 | <TD VAlign=top> |
---|
| 383 | |
---|
| 384 | </TD> |
---|
| 385 | </tr> |
---|
| 386 | </table> |
---|
| 387 | <h3>Complexity guarantees</h3> |
---|
| 388 | |
---|
| 389 | <tt>begin()</tt> and <tt>end()</tt> are amortized constant time. |
---|
| 390 | <P> |
---|
| 391 | <tt>size()</tt> is at most linear in the Collection's |
---|
| 392 | size. <tt>empty()</tt> is amortized constant time. |
---|
| 393 | <P> |
---|
| 394 | <tt>swap()</tt> is at most linear in the size of the two collections. |
---|
| 395 | <h3>Invariants</h3> |
---|
| 396 | <Table border> |
---|
| 397 | <TR> |
---|
| 398 | <TD VAlign=top> |
---|
| 399 | Valid range |
---|
| 400 | </TD> |
---|
| 401 | <TD VAlign=top> |
---|
| 402 | For any Collection <tt>a</tt>, <tt>[a.begin(), a.end())</tt> is a valid |
---|
| 403 | range. |
---|
| 404 | </TD> |
---|
| 405 | </TR> |
---|
| 406 | <TR> |
---|
| 407 | <TD VAlign=top> |
---|
| 408 | Range size |
---|
| 409 | </TD> |
---|
| 410 | <TD VAlign=top> |
---|
| 411 | <tt>a.size()</tt> is equal to the distance from <tt>a.begin()</tt> to <tt>a.end()</tt>. |
---|
| 412 | </TD> |
---|
| 413 | </TR> |
---|
| 414 | <TR> |
---|
| 415 | <TD VAlign=top> |
---|
| 416 | Completeness |
---|
| 417 | </TD> |
---|
| 418 | <TD VAlign=top> |
---|
| 419 | An algorithm that iterates through the range <tt>[a.begin(), a.end())</tt> |
---|
| 420 | will pass through every element of <tt>a</tt>. |
---|
| 421 | </TD> |
---|
| 422 | </tr> |
---|
| 423 | </table> |
---|
| 424 | |
---|
| 425 | |
---|
| 426 | <h3>Models</h3> |
---|
| 427 | <UL> |
---|
| 428 | <LI> <tt>array</tt> |
---|
| 429 | <LI> <tt>array_ptr</tt> |
---|
| 430 | <LI> <tt>vector<bool></tt> |
---|
| 431 | </UL> |
---|
| 432 | |
---|
| 433 | |
---|
| 434 | <h3>Collection Refinements</h3> |
---|
| 435 | |
---|
| 436 | There are quite a few concepts that refine the Collection concept, |
---|
| 437 | similar to the concepts that refine the Container concept. Here |
---|
| 438 | is a brief overview of the refining concepts. |
---|
| 439 | |
---|
| 440 | <h4>ForwardCollection</h4> |
---|
| 441 | The elements are arranged in some order that |
---|
| 442 | does not change spontaneously from one iteration to the next. As |
---|
| 443 | a result, a ForwardCollection is |
---|
| 444 | <A |
---|
| 445 | href="http://www.sgi.com/tech/stl/EqualityComparable.html">EqualityComparable</A> |
---|
| 446 | and |
---|
| 447 | <A |
---|
| 448 | href="http://www.sgi.com/tech/stl/LessThanComparable.html">LessThanComparable</A>. |
---|
| 449 | In addition, the iterator type of a ForwardCollection is a |
---|
| 450 | MultiPassInputIterator which is just an InputIterator with the added |
---|
| 451 | requirements that the iterator can be used to make multiple passes |
---|
| 452 | through a range, and that if <tt>it1 == it2</tt> and <tt>it1</tt> is |
---|
| 453 | dereferenceable then <tt>++it1 == ++it2</tt>. The ForwardCollection |
---|
| 454 | also has a <tt>front()</tt> method. |
---|
| 455 | |
---|
| 456 | <p> |
---|
| 457 | <Table border> |
---|
| 458 | <TR> |
---|
| 459 | <TH> |
---|
| 460 | Name |
---|
| 461 | </TH> |
---|
| 462 | <TH> |
---|
| 463 | Expression |
---|
| 464 | </TH> |
---|
| 465 | <TH> |
---|
| 466 | Return type |
---|
| 467 | </TH> |
---|
| 468 | <TH> |
---|
| 469 | Semantics |
---|
| 470 | </TH> |
---|
| 471 | </TR> |
---|
| 472 | |
---|
| 473 | <TR> |
---|
| 474 | <TD VAlign=top> |
---|
| 475 | Front |
---|
| 476 | </TD> |
---|
| 477 | <TD VAlign=top> |
---|
| 478 | <tt>a.front()</tt> |
---|
| 479 | </TD> |
---|
| 480 | <TD VAlign=top> |
---|
| 481 | <tt>reference</tt> if <tt>a</tt> is mutable, <br> <tt>const_reference</tt> |
---|
| 482 | otherwise. |
---|
| 483 | </TD> |
---|
| 484 | <TD VAlign=top> |
---|
| 485 | Equivalent to <tt>*(a.begin())</tt>. |
---|
| 486 | </TD> |
---|
| 487 | </TR> |
---|
| 488 | |
---|
| 489 | </table> |
---|
| 490 | |
---|
| 491 | |
---|
| 492 | <h4>ReversibleCollection</h4> |
---|
| 493 | |
---|
| 494 | The container provides access to iterators that traverse in both |
---|
| 495 | directions (forward and reverse). The iterator type must meet all of |
---|
| 496 | the requirements of |
---|
| 497 | <a href="http://www.sgi.com/tech/stl/BidirectionalIterator.html">BidirectionalIterator</a> |
---|
| 498 | except that the reference type does not have to be a real C++ |
---|
| 499 | reference. The ReversibleCollection adds the following requirements |
---|
| 500 | to those of ForwardCollection. |
---|
| 501 | <p> |
---|
| 502 | |
---|
| 503 | <Table border> |
---|
| 504 | <TR> |
---|
| 505 | <TH> |
---|
| 506 | Name |
---|
| 507 | </TH> |
---|
| 508 | <TH> |
---|
| 509 | Expression |
---|
| 510 | </TH> |
---|
| 511 | <TH> |
---|
| 512 | Return type |
---|
| 513 | </TH> |
---|
| 514 | <TH> |
---|
| 515 | Semantics |
---|
| 516 | </TH> |
---|
| 517 | </TR> |
---|
| 518 | <TR> |
---|
| 519 | <TD VAlign=top> |
---|
| 520 | Beginning of range |
---|
| 521 | </TD> |
---|
| 522 | <TD VAlign=top> |
---|
| 523 | <tt>a.rbegin()</tt> |
---|
| 524 | </TD> |
---|
| 525 | <TD VAlign=top> |
---|
| 526 | <tt>reverse_iterator</tt> if <tt>a</tt> is mutable, |
---|
| 527 | <tt>const_reverse_iterator</tt> otherwise. |
---|
| 528 | </TD> |
---|
| 529 | <TD VAlign=top> |
---|
| 530 | Equivalent to <tt>X::reverse_iterator(a.end())</tt>. |
---|
| 531 | </TD> |
---|
| 532 | </TR> |
---|
| 533 | <TR> |
---|
| 534 | <TD VAlign=top> |
---|
| 535 | End of range |
---|
| 536 | </TD> |
---|
| 537 | <TD VAlign=top> |
---|
| 538 | <tt>a.rend()</tt> |
---|
| 539 | </TD> |
---|
| 540 | <TD VAlign=top> |
---|
| 541 | <tt>reverse_iterator</tt> if <tt>a</tt> is mutable, |
---|
| 542 | <tt>const_reverse_iterator</tt> otherwise. |
---|
| 543 | </TD> |
---|
| 544 | <TD VAlign=top> |
---|
| 545 | Equivalent to <tt>X::reverse_iterator(a.begin())</tt>. |
---|
| 546 | </TD> |
---|
| 547 | </tr> |
---|
| 548 | |
---|
| 549 | <TR> |
---|
| 550 | <TD VAlign=top> |
---|
| 551 | Back |
---|
| 552 | </TD> |
---|
| 553 | <TD VAlign=top> |
---|
| 554 | <tt>a.back()</tt> |
---|
| 555 | </TD> |
---|
| 556 | <TD VAlign=top> |
---|
| 557 | <tt>reference</tt> if <tt>a</tt> is mutable, <br> <tt>const_reference</tt> |
---|
| 558 | otherwise. |
---|
| 559 | </TD> |
---|
| 560 | <TD VAlign=top> |
---|
| 561 | Equivalent to <tt>*(--a.end())</tt>. |
---|
| 562 | </TD> |
---|
| 563 | </TR> |
---|
| 564 | |
---|
| 565 | </table> |
---|
| 566 | |
---|
| 567 | <h4>SequentialCollection</h4> |
---|
| 568 | |
---|
| 569 | The elements are arranged in a strict linear order. No extra methods |
---|
| 570 | are required. |
---|
| 571 | |
---|
| 572 | <h4>RandomAccessCollection</h4> |
---|
| 573 | |
---|
| 574 | The iterators of a RandomAccessCollection satisfy all of the |
---|
| 575 | requirements of <a |
---|
| 576 | href="http://www.sgi.com/tech/stl/RandomAccessIterator.html">RandomAccessIterator</a> |
---|
| 577 | except that the reference type does not have to be a real C++ |
---|
| 578 | reference. In addition, a RandomAccessCollection provides |
---|
| 579 | an element access operator. |
---|
| 580 | |
---|
| 581 | <p> |
---|
| 582 | |
---|
| 583 | <Table border> |
---|
| 584 | <TR> |
---|
| 585 | <TH> |
---|
| 586 | Name |
---|
| 587 | </TH> |
---|
| 588 | <TH> |
---|
| 589 | Expression |
---|
| 590 | </TH> |
---|
| 591 | <TH> |
---|
| 592 | Return type |
---|
| 593 | </TH> |
---|
| 594 | <TH> |
---|
| 595 | Semantics |
---|
| 596 | </TH> |
---|
| 597 | </TR> |
---|
| 598 | <TR> |
---|
| 599 | <TD VAlign=top> |
---|
| 600 | Element Access |
---|
| 601 | </TD> |
---|
| 602 | <TD VAlign=top> |
---|
| 603 | <tt>a[n]</tt> |
---|
| 604 | </TD> |
---|
| 605 | <TD VAlign=top> |
---|
| 606 | <tt>reference</tt> if <tt>a</tt> is mutable, |
---|
| 607 | <tt>const_reference</tt> otherwise. |
---|
| 608 | </TD> |
---|
| 609 | <TD VAlign=top> |
---|
| 610 | Returns the nth element of the Collection. |
---|
| 611 | <tt>n</tt> must be convertible to <tt>size_type</tt>. |
---|
| 612 | Precondition: <tt>0 <= n < a.size()</tt>. |
---|
| 613 | </TD> |
---|
| 614 | </TR> |
---|
| 615 | |
---|
| 616 | </table> |
---|
| 617 | |
---|
| 618 | <h3>Notes</h3> |
---|
| 619 | |
---|
| 620 | <P><A name="1">[1]</A> |
---|
| 621 | |
---|
| 622 | The reference type does not have to be a real C++ reference. The |
---|
| 623 | requirements of the reference type depend on the context within which |
---|
| 624 | the Collection is being used. Specifically it depends on the |
---|
| 625 | requirements the context places on the value type of the Collection. |
---|
| 626 | The reference type of the Collection must meet the same requirements |
---|
| 627 | as the value type. In addition, the reference objects must be |
---|
| 628 | equivalent to the value type objects in the collection (which is |
---|
| 629 | trivially true if they are the same object). Also, in a mutable |
---|
| 630 | Collection, an assignment to the reference object must result in an |
---|
| 631 | assignment to the object in the Collection (again, which is trivially |
---|
| 632 | true if they are the same object, but non-trivial if the reference |
---|
| 633 | type is a proxy class). |
---|
| 634 | |
---|
| 635 | <h3>See also</h3> |
---|
| 636 | <A href="http://www.sgi.com/tech/stl/Container.html">Container</A> |
---|
| 637 | |
---|
| 638 | |
---|
| 639 | <br> |
---|
| 640 | <HR> |
---|
| 641 | <TABLE> |
---|
| 642 | <TR valign=top> |
---|
| 643 | <TD nowrap>Copyright © 2000</TD><TD> |
---|
| 644 | <A HREF=http://www.boost.org/people/jeremy_siek.htm>Jeremy Siek</A>, Univ.of Notre Dame and C++ Library & Compiler Group/SGI (<A HREF="mailto:jsiek@engr.sgi.com">jsiek@engr.sgi.com</A>) |
---|
| 645 | </TD></TR></TABLE> |
---|
| 646 | |
---|
| 647 | </BODY> |
---|
| 648 | </HTML> |
---|