1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 2<html> 3<head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> 4<title>Tables</title> 5</head> 6 7<body bgcolor="#ffffff"> 8 9<h1>Tables</h1> 10 11<p>Most of the requirements on containers are presented in the ISO standard 12 in the form of tables. In order to avoid massive duplication of effort 13 while documenting all the classes, we follow the standard's lead and 14 present the base information here. Individual classes will only document 15 their departures from these tables (removed functions, additional functions, 16 changes, etc). 17</p> 18 19<p>We will not try to duplicate all of the surrounding text (footnotes, 20 explanations, etc.) from the standard, because that would also entail a 21 duplication of effort. Some of the surrounding text has been paraphrased 22 here for clarity. If you are uncertain about the meaning or interpretation 23 of these notes, consult a good textbook, and/or purchase your own copy of 24 the standard (it's cheap, see our FAQ). 25</p> 26 27<p>The table numbers are the same as those used in the standard. Tables can 28 be jumped to using their number, e.g., "tables.html#67". Only 29 Tables 65 through 69 are presented. Some of the active Defect Reports 30 are also noted or incorporated. 31</p> 32 33<hr /> 34 35<a name="65"><p> 36<table cellpadding="3" cellspacing="5" align="center" rules="rows" border="3" 37 cols="5" title="Table 65"> 38<caption><h2>Table 65 --- Container Requirements</h2></caption> 39<tr><th colspan="5"> 40Anything calling itself a container must meet these minimum requirements. 41</th></tr> 42<tr> 43<td><strong>expression</strong></td> 44<td><strong>result type</strong></td> 45<td><strong>operational semantics</strong></td> 46<td><strong>notes, pre-/post-conditions, assertions</strong></td> 47<td><strong>complexity</strong></td> 48</tr> 49 50<tr> 51<td>X::value_type</td> 52<td>T</td> 53<td> </td> 54<td>T is Assignable</td> 55<td>compile time</td> 56</tr> 57 58<tr> 59<td>X::reference</td> 60<td>lvalue of T</td> 61<td> </td> 62<td> </td> 63<td>compile time</td> 64</tr> 65 66<tr> 67<td>X::const_reference</td> 68<td>const lvalue of T</td> 69<td> </td> 70<td> </td> 71<td>compile time</td> 72</tr> 73 74<tr> 75<td>X::iterator</td> 76<td>iterator type pointing to T</td> 77<td> </td> 78<td>Any iterator category except output iterator. 79 Convertible to X::const_iterator.</td> 80<td>compile time</td> 81</tr> 82 83<tr> 84<td>X::const_iterator</td> 85<td>iterator type pointing to const T</td> 86<td> </td> 87<td>Any iterator category except output iterator.</td> 88<td>compile time</td> 89</tr> 90 91<tr> 92<td>X::difference_type</td> 93<td>signed integral type</td> 94<td> </td> 95<td>identical to the difference type of X::iterator and X::const_iterator</td> 96<td>compile time</td> 97</tr> 98 99<tr> 100<td>X::size_type</td> 101<td>unsigned integral type</td> 102<td> </td> 103<td>size_type can represent any non-negative value of difference_type</td> 104<td>compile time</td> 105</tr> 106 107<tr> 108<td>X u;</td> 109<td> </td> 110<td> </td> 111<td>post: u.size() == 0</td> 112<td>constant</td> 113</tr> 114 115<tr> 116<td>X();</td> 117<td> </td> 118<td> </td> 119<td>X().size == 0</td> 120<td>constant</td> 121</tr> 122 123<tr> 124<td>X(a);</td> 125<td> </td> 126<td> </td> 127<td>a == X(a)</td> 128<td>linear</td> 129</tr> 130 131<tr> 132<td>X u(a);<br />X u = a;</td> 133<td> </td> 134<td> </td> 135<td>post: u == a. Equivalent to: X u; u = a;</td> 136<td>linear</td> 137</tr> 138 139<tr> 140<td>(&a)->~X();</td> 141<td>void</td> 142<td> </td> 143<td>dtor is applied to every element of a; all the memory is deallocated</td> 144<td>linear</td> 145</tr> 146 147<tr> 148<td>a.begin()</td> 149<td>iterator; const_iterator for constant a</td> 150<td> </td> 151<td> </td> 152<td>constant</td> 153</tr> 154 155<tr> 156<td>a.end()</td> 157<td>iterator; const_iterator for constant a</td> 158<td> </td> 159<td> </td> 160<td>constant</td> 161</tr> 162 163<tr> 164<td>a == b</td> 165<td>convertible to bool</td> 166<td> </td> 167<td>== is an equivalence relation. a.size()==b.size() && 168 equal(a.begin(),a.end(),b.begin())</td> 169<td>linear</td> 170</tr> 171 172<tr> 173<td>a != b</td> 174<td>convertible to bool</td> 175<td> </td> 176<td>equivalent to !(a==b)</td> 177<td>linear</td> 178</tr> 179 180<tr> 181<td>a.swap(b)</td> 182<td>void</td> 183<td> </td> 184<td>swap(a,b)</td> 185<td>may or may not have constant complexity</td> 186</tr> 187 188<tr> 189<td>r = a</td> 190<td>X&</td> 191<td> </td> 192<td>r == a</td> 193<td>linear</td> 194</tr> 195 196<!-- a fifth column, "operation semantics," magically appears in the table 197 at this point... wtf? --> 198<tr> 199<td>a.size()</td> 200<td>size_type</td> 201<td>a.end() - a.begin()</td> 202<td> </td> 203<td>may or may not have constant complexity</td> 204</tr> 205 206<tr> 207<td>a.max_size()</td> 208<td>size_type</td> 209<td>size() of the largest possible container</td> 210<td> </td> 211<td>may or may not have constant complexity</td> 212</tr> 213 214<tr> 215<td>a.empty()</td> 216<td>convertible to bool</td> 217<td>a.size() == 0</td> 218<td> </td> 219<td>constant</td> 220</tr> 221 222<tr> 223<td>a < b</td> 224<td>convertible to bool</td> 225<td>lexographical_compare( a.begin, a.end(), b.begin(), b.end())</td> 226<td>pre: < is defined for T and is a total ordering relation</td> 227<td>linear</td> 228</tr> 229 230<tr> 231<td>a > b</td> 232<td>convertible to bool</td> 233<td>b < a</td> 234<td> </td> 235<td>linear</td> 236</tr> 237 238<tr> 239<td>a <= b</td> 240<td>convertible to bool</td> 241<td>!(a > b)</td> 242<td> </td> 243<td>linear</td> 244</tr> 245 246<tr> 247<td>a >= b</td> 248<td>convertible to bool</td> 249<td>!(a < b)</td> 250<td> </td> 251<td>linear</td> 252</tr> 253</table title="Table 65"></p></a> 254 255 256<a name="66"><p> 257<table cellpadding="3" cellspacing="5" align="center" rules="rows" border="3" 258 cols="4" title="Table 66"> 259<caption><h2>Table 66 --- Reversible Container Requirements</h2></caption> 260<tr><th colspan="4"> 261If a container's iterator is bidirectional or random-access, then the 262container also meets these requirements. 263Deque, list, vector, map, multimap, set, and multiset are such containers. 264</th></tr> 265<tr> 266<td><strong>expression</strong></td> 267<td><strong>result type</strong></td> 268<td><strong>notes, pre-/post-conditions, assertions</strong></td> 269<td><strong>complexity</strong></td> 270</tr> 271 272<tr> 273<td>X::reverse_iterator</td> 274<td>iterator type pointing to T</td> 275<td>reverse_iterator<iterator></td> 276<td>compile time</td> 277</tr> 278 279<tr> 280<td>X::const_reverse_iterator</td> 281<td>iterator type pointing to const T</td> 282<td>reverse_iterator<const_iterator></td> 283<td>compile time</td> 284</tr> 285 286<tr> 287<td>a.rbegin()</td> 288<td>reverse_iterator; const_reverse_iterator for constant a</td> 289<td>reverse_iterator(end())</td> 290<td>constant</td> 291</tr> 292 293<tr> 294<td>a.rend()</td> 295<td>reverse_iterator; const_reverse_iterator for constant a</td> 296<td>reverse_iterator(begin())</td> 297<td>constant</td> 298</tr> 299</table title="Table 66"></p></a> 300 301 302<a name="67"><p> 303<table cellpadding="3" cellspacing="5" align="center" rules="rows" border="3" 304 cols="3" title="Table 67"> 305<caption><h2>Table 67 --- Sequence Requirements</h2></caption> 306<tr><th colspan="3"> 307These are in addition to the requirements of <a href="#65">containers</a>. 308Deque, list, and vector are such containers. 309</th></tr> 310<tr> 311<td><strong>expression</strong></td> 312<td><strong>result type</strong></td> 313<td><strong>notes, pre-/post-conditions, assertions</strong></td> 314</tr> 315 316<tr> 317<td>X(n,t)<br />X a(n,t)</td> 318<td> </td> 319<td>constructs a sequence with n copies of t<br />post: size() == n</td> 320</tr> 321 322<tr> 323<td>X(i,j)<br />X a(i,j)</td> 324<td> </td> 325<td>constructs a sequence equal to the range [i,j)<br /> 326 post: size() == distance(i,j)</td> 327</tr> 328 329<tr> 330<td>a.insert(p,t)</td> 331<td>iterator (points to the inserted copy of t)</td> 332<td>inserts a copy of t before p</td> 333</tr> 334 335<tr> 336<td>a.insert(p,n,t)</td> 337<td>void</td> 338<td>inserts n copies of t before p</td> 339</tr> 340 341<tr> 342<td>a.insert(p,i,j)</td> 343<td>void</td> 344<td>inserts copies of elements in [i,j) before p<br /> 345 pre: i, j are not iterators into a</td> 346</tr> 347 348<tr> 349<td>a.erase(q)</td> 350<td>iterator (points to the element following q (prior to erasure))</td> 351<td>erases the element pointed to by q</td> 352</tr> 353 354<tr> 355<td>a.erase(q1,q1)</td> 356<td>iterator (points to the element pointed to by q2 (prior to erasure))</td> 357<td>erases the elements in the range [q1,q2)</td> 358</tr> 359 360<tr> 361<td>a.clear()</td> 362<td>void</td> 363<td>erase(begin(),end())<br />post: size() == 0</td> 364</tr> 365</table title="Table 67"></p></a> 366 367 368<a name="68"><p> 369<table cellpadding="3" cellspacing="5" align="center" rules="rows" border="3" 370 cols="4" title="Table 68"> 371<caption><h2>Table 68 --- Optional Sequence Operations</h2></caption> 372<tr><th colspan="4"> 373These operations are only included in containers when the operation can be 374done in constant time. 375</th></tr> 376<tr> 377<td><strong>expression</strong></td> 378<td><strong>result type</strong></td> 379<td><strong>operational semantics</strong></td> 380<td><strong>container</strong></td> 381</tr> 382 383<tr> 384<td>a.front()</td> 385<td>reference; const_reference for constant a</td> 386<td>*a.begin()</td> 387<td>vector, list, deque</td> 388</tr> 389 390<tr> 391<td>a.back()</td> 392<td>reference; const_reference for constant a</td> 393<td>*--a.end()</td> 394<td>vector, list, deque</td> 395</tr> 396 397<tr> 398<td>a.push_front(x)</td> 399<td>void</td> 400<td>a.insert(a.begin(),x)</td> 401<td>list, deque</td> 402</tr> 403 404<tr> 405<td>a.push_back(x)</td> 406<td>void</td> 407<td>a.insert(a.end(),x)</td> 408<td>vector, list, deque</td> 409</tr> 410 411<tr> 412<td>a.pop_front()</td> 413<td>void</td> 414<td>a.erase(a.begin())</td> 415<td>list, deque</td> 416</tr> 417 418<tr> 419<td>a.pop_back()</td> 420<td>void</td> 421<td>a.erase(--a.end())</td> 422<td>vector, list, deque</td> 423</tr> 424 425<tr> 426<td>a[n]</td> 427<td>reference; const_reference for constant a</td> 428<td>*(a.begin() + n)</td> 429<td>vector, deque</td> 430</tr> 431 432<tr> 433<td>a.at(n)</td> 434<td>reference; const_reference for constant a</td> 435<td>*(a.begin() + n)<br />throws out_of_range if n>=a.size()</td> 436<td>vector, deque</td> 437</tr> 438</table title="Table 68"></p></a> 439 440 441<a name="69"><p> 442<table cellpadding="3" cellspacing="5" align="center" rules="rows" border="3" 443 cols="4" title="Table 69"> 444<caption><h2>Table 69 --- Associative Container Requirements</h2></caption> 445<tr><th colspan="4"> 446These are in addition to the requirements of <a href="#65">containers</a>. 447Map, multimap, set, and multiset are such containers. An associative 448container supports <em>unique keys</em> (and is written as 449<code>a_uniq</code> instead of <code>a</code>) if it may contain at most 450one element for each key. Otherwise it supports <em>equivalent keys</em> 451(and is written <code>a_eq</code>). Examples of the former are set and map, 452examples of the latter are multiset and multimap. 453</th></tr> 454<tr> 455<td><strong>expression</strong></td> 456<td><strong>result type</strong></td> 457<td><strong>notes, pre-/post-conditions, assertions</strong></td> 458<td><strong>complexity</strong></td> 459</tr> 460 461<tr> 462<td>X::key_type</td> 463<td>Key</td> 464<td>Key is Assignable</td> 465<td>compile time</td> 466</tr> 467 468<tr> 469<td>X::key_compare</td> 470<td>Compare</td> 471<td>defaults to less<key_type></td> 472<td>compile time</td> 473</tr> 474 475<tr> 476<td>X::value_compare</td> 477<td>a binary predicate type</td> 478<td>same as key_compare for set and multiset; an ordering relation on 479 pairs induced by the first component (Key) for map and multimap</td> 480<td>compile time</td> 481</tr> 482 483<tr> 484<td>X(c)<br />X a(c)</td> 485<td> </td> 486<td>constructs an empty container which uses c as a comparison object</td> 487<td>constant</td> 488</tr> 489 490<tr> 491<td>X()<br />X a</td> 492<td> </td> 493<td>constructs an empty container using Compare() as a comparison object</td> 494<td>constant</td> 495</tr> 496 497<tr> 498<td>X(i,j,c)<br />X a(i,j,c)</td> 499<td> </td> 500<td>constructs an empty container and inserts elements from the range [i,j) 501 into it; uses c as a comparison object</td> 502<td>NlogN in general where N is distance(i,j); linear if [i,j) is 503 sorted with value_comp()</td> 504</tr> 505 506<tr> 507<td>X(i,j)<br />X a(i,j)</td> 508<td> </td> 509<td>same as previous, but uses Compare() as a comparison object</td> 510<td>same as previous</td> 511</tr> 512 513<tr> 514<td>a.key_comp()</td> 515<td>X::key_compare</td> 516<td>returns the comparison object out of which a was constructed</td> 517<td>constant</td> 518</tr> 519 520<tr> 521<td>a.value_comp()</td> 522<td>X::value_compare</td> 523<td>returns an object constructed out of the comparison object</td> 524<td>constant</td> 525</tr> 526 527<tr> 528<td>a_uniq.insert(t)</td> 529<td>pair<iterator,bool></td> 530<td>"Inserts t if and only if there is no element in the container with 531 key equivalent to the key of t. The bool component of the returned pair 532 is true -iff- the insertion took place, and the iterator component of 533 the pair points to the element with key equivalent to the key of 534 t."</td> <!-- DR 316 --> 535<td>logarithmic</td> 536</tr> 537 538<tr> 539<td>a_eq.insert(t)</td> 540<td>iterator</td> 541<td>inserts t, returns the iterator pointing to the inserted element</td> 542<td>logarithmic</td> 543</tr> 544 545<tr> 546<td>a.insert(p,t)</td> 547<td>iterator</td> 548<td>possibly inserts t (depending on whether a_uniq or a_eq); returns iterator 549 pointing to the element with key equivalent to the key of t; iterator p 550 is a hint pointing to where the insert should start to search</td> 551<td>logarithmic in general, amortized constant if t is inserted right 552 after p<br /> 553 <strong>[but see DR 233 and <a href=" 554 http://gcc.gnu.org/onlinedocs/libstdc++/23_containers/howto.html#4">our 555 specific notes</a>]</strong></td> 556</tr> 557 558<tr> 559<td>a.insert(i,j)</td> 560<td>void</td> 561<td>pre: i, j are not iterators into a. possibly inserts each element from 562 the range [i,j) (depending on whether a_uniq or a_eq)</td> 563<td>Nlog(size()+N) where N is distance(i,j) in general</td> <!-- DR 264 --> 564</tr> 565 566<tr> 567<td>a.erase(k)</td> 568<td>size_type</td> 569<td>erases all elements with key equivalent to k; returns number of erased 570 elements</td> 571<td>log(size()) + count(k)</td> 572</tr> 573 574<tr> 575<td>a.erase(q)</td> 576<td>void</td> 577<td>erases the element pointed to by q</td> 578<td>amortized constant</td> 579</tr> 580 581<tr> 582<td>a.erase(q1,q2)</td> 583<td>void</td> 584<td>erases all the elements in the range [q1,q2)</td> 585<td>log(size()) + distance(q1,q2)</td> 586</tr> 587 588<tr> 589<td>a.clear()</td> 590<td>void</td> 591<td>erases everything; post: size() == 0</td> 592<td>linear</td> <!-- DR 224 --> 593</tr> 594 595<tr> 596<td>a.find(k)</td> 597<td>iterator; const_iterator for constant a</td> 598<td>returns iterator pointing to element with key equivalent to k, or 599 a.end() if no such element found</td> 600<td>logarithmic</td> 601</tr> 602 603<tr> 604<td>a.count(k)</td> 605<td>size_type</td> 606<td>returns number of elements with key equivalent to k</td> 607<td>log(size()) + count(k)</td> 608</tr> 609 610<tr> 611<td>a.lower_bound(k)</td> 612<td>iterator; const_iterator for constant a</td> 613<td>returns iterator pointing to the first element with key not less than k</td> 614<td>logarithmic</td> 615</tr> 616 617<tr> 618<td>a.upper_bound(k)</td> 619<td>iterator; const_iterator for constant a</td> 620<td>returns iterator pointing to the first element with key greater than k</td> 621<td>logarithmic</td> 622</tr> 623 624<tr> 625<td>a.equal_range(k)</td> 626<td>pair<iterator,iterator>; 627 pair<const_iterator, const_iterator> for constant a</td> 628<td>equivalent to make_pair(a.lower_bound(k), a.upper_bound(k))</td> 629<td>logarithmic</td> 630</tr> 631</table title="Table 69"></p></a> 632 633 634<hr /> 635<p class="smallertext"><em> 636See <a href="mainpage.html">mainpage.html</a> for copying conditions. 637See <a href="http://gcc.gnu.org/libstdc++/">the libstdc++ homepage</a> 638for more information. 639</em></p> 640 641 642</body> 643</html> 644 645