1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201
|
<HTML>
<!--
-- Copyright (c) 1996-1999
-- Silicon Graphics Computer Systems, Inc.
--
-- Permission to use, copy, modify, distribute and sell this software
-- and its documentation for any purpose is hereby granted without fee,
-- provided that the above copyright notice appears in all copies and
-- that both that copyright notice and this permission notice appear
-- in supporting documentation. Silicon Graphics makes no
-- representations about the suitability of this software for any
-- purpose. It is provided "as is" without express or implied warranty.
--
-- Copyright (c) 1994
-- Hewlett-Packard Company
--
-- Permission to use, copy, modify, distribute and sell this software
-- and its documentation for any purpose is hereby granted without fee,
-- provided that the above copyright notice appears in all copies and
-- that both that copyright notice and this permission notice appear
-- in supporting documentation. Hewlett-Packard Company makes no
-- representations about the suitability of this software for any
-- purpose. It is provided "as is" without express or implied warranty.
--
-->
<Head>
<Title>slist<T, Alloc></Title>
<!-- Generated by htmldoc -->
</HEAD>
<BODY BGCOLOR="#ffffff" LINK="#0000ee" TEXT="#000000" VLINK="#551a8b"
ALINK="#ff0000">
<IMG SRC="CorpID.gif"
ALT="SGI" HEIGHT="43" WIDTH="151">
<!--end header-->
<BR Clear>
<H1>slist<T, Alloc></H1>
<Table CellPadding=0 CellSpacing=0 width=100%>
<TR>
<TD Align=left><Img src = "containers.gif" Alt="" WIDTH = "194" HEIGHT = "38" ></TD>
<TD Align=right><Img src = "type.gif" Alt="" WIDTH = "194" HEIGHT = "39" ></TD>
</TR>
<TR>
<TD Align=left VAlign=top><b>Category</b>: containers</TD>
<TD Align=right VAlign=top><b>Component type</b>: type</TD>
</TR>
</Table>
<h3>Description</h3>
An <tt>slist</tt> is a singly linked list: a list where each element is
linked to the next element, but not to the previous element. <A href="#1">[1]</A> That is,
it is a <A href="Sequence.html">Sequence</A> that supports forward but not backward traversal,
and (amortized) constant time insertion and removal of elements.
<tt>Slist</tt>s, like <tt><A href="List.html">list</A></tt>s, have the important property that insertion
and splicing do not invalidate iterators to list elements, and that
even removal invalidates only the iterators that point to the elements
that are removed. The ordering of iterators may be changed (that is,
<tt>slist<T>::iterator</tt> might have a different predecessor or successor
after a list operation than it did before), but the iterators
themselves will not be invalidated or made to point to different
elements unless that invalidation or mutation is explicit. <A href="#2">[2]</A>
<P>
The main difference between <tt>slist</tt> and <tt><A href="List.html">list</A></tt> is that <tt><A href="List.html">list</A></tt>'s
iterators are <A href="BidirectionalIterator.html">bidirectional iterators</A>, while <tt>slist</tt>'s iterators
are <A href="ForwardIterator.html">forward iterators</A>. This means that <tt>slist</tt> is less versatile
than <tt><A href="List.html">list</A></tt>; frequently, however, <A href="BidirectionalIterator.html">bidirectional iterators</A>
are unnecessary. You should usually use <tt>slist</tt> unless you actually
need the extra functionality of <tt><A href="List.html">list</A></tt>, because singly linked
lists are smaller and faster than double linked lists.
<P>
<b>Important performance note</b>: like every other <A href="Sequence.html">Sequence</A>, <tt>slist</tt>
defines the member functions <tt>insert</tt> and <tt>erase</tt>. Using these member
functions carelessly, however, can result in disastrously slow
programs. The problem is that <tt>insert</tt>'s first argument is an
iterator <tt>pos</tt>, and that it inserts the new element(s) <i>before</i>
<tt>pos</tt>. This means that <tt>insert</tt> must find the iterator just
before <tt>pos</tt>; this is a constant-time operation for <tt><A href="List.html">list</A></tt>,
since <tt><A href="List.html">list</A></tt> has bidirectional iterators, but for <tt>slist</tt>
it must find that iterator by traversing the list from the beginning
up to <tt>pos</tt>. In other words: <tt>insert</tt> and <tt>erase</tt> are slow operations
anywhere but near the beginning of the <tt>slist</tt>.
<P>
<tt>Slist</tt> provides the member functions <tt>insert_after</tt> and
<tt>erase_after</tt>, which are constant time operations: you should always
use <tt>insert_after</tt> and <tt>erase_after</tt> whenever possible. If you find
that <tt>insert_after</tt> and <tt>erase_after</tt> aren't adequate for your needs,
and that you often need to use <tt>insert</tt> and <tt>erase</tt> in the middle of
the list, then you should probably use <tt><A href="List.html">list</A></tt> instead of <tt>slist</tt>.
<h3>Definition</h3>
Defined in the header <A href="slist">slist</A>, and in the backward-compatibility
header <A href="slist.h">slist.h</A>.
The <tt>slist</tt> class, and the <A href="slist">slist</A> header, are an SGI extension;
they are not part of the C++ standard.
<h3>Example</h3>
<pre>
int main() {
slist<int> L;
L.push_front(0);
L.push_front(1);
L.insert_after(L.begin(), 2);
<A href="copy.html">copy</A>(L.begin(), L.end(), // The output is 1 2 0
<A href="ostream_iterator.html">ostream_iterator</A><int>(cout, " "));
cout << endl;
slist<int>::iterator back = L.previous(L.end());
back = L.insert_after(back, 3);
back = L.insert_after(back, 4);
back = L.insert_after(back, 5);
<A href="copy.html">copy</A>(L.begin(), L.end(), // The output is 1 2 0 3 4 5
<A href="ostream_iterator.html">ostream_iterator</A><int>(cout, " "));
cout << endl;
}
</pre>
<h3>Template parameters</h3>
<Table border>
<TR>
<TH>
Parameter
</TH>
<TH>
Description
</TH>
<TH>
Default
</TH>
</TR>
<TR>
<TD VAlign=top>
<tt>T</tt>
</TD>
<TD VAlign=top>
The <tt>slist</tt>'s value type: the type of object that is stored in the list.
</TD>
<TD VAlign=top>
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>Alloc</tt>
</TD>
<TD VAlign=top>
The <tt>slist</tt>'s allocator, used for all internal memory management.
</TD>
<TD VAlign=top>
<tt><A href="Allocators.html">alloc</A></tt>
</TD>
</tr>
</table>
<h3>Model of</h3>
<A href="FrontInsertionSequence.html">Front Insertion Sequence</A>
<h3>Type requirements</h3>
None, except for those imposed by the requirements of
<A href="FrontInsertionSequence.html">Front Insertion Sequence</A>.
<h3>Public base classes</h3>
None.
<h3>Members</h3>
<Table border>
<TR>
<TH>
Member
</TH>
<TH>
Where defined
</TH>
<TH>
Description
</TH>
</TR>
<TR>
<TD VAlign=top>
<tt>value_type</tt>
</TD>
<TD VAlign=top>
<A href="Container.html">Container</A>
</TD>
<TD VAlign=top>
The type of object, <tt>T</tt>, stored in the <tt>slist</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>pointer</tt>
</TD>
<TD VAlign=top>
<A href="Container.html">Container</A>
</TD>
<TD VAlign=top>
Pointer to <tt>T</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>reference</tt>
</TD>
<TD VAlign=top>
<A href="Container.html">Container</A>
</TD>
<TD VAlign=top>
Reference to <tt>T</tt>
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>const_reference</tt>
</TD>
<TD VAlign=top>
<A href="Container.html">Container</A>
</TD>
<TD VAlign=top>
Const reference to <tt>T</tt>
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>size_type</tt>
</TD>
<TD VAlign=top>
<A href="Container.html">Container</A>
</TD>
<TD VAlign=top>
An unsigned integral type.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>difference_type</tt>
</TD>
<TD VAlign=top>
<A href="Container.html">Container</A>
</TD>
<TD VAlign=top>
A signed integral type.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>iterator</tt>
</TD>
<TD VAlign=top>
<A href="Container.html">Container</A>
</TD>
<TD VAlign=top>
Iterator used to iterate through an <tt>slist</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>const_iterator</tt>
</TD>
<TD VAlign=top>
<A href="Container.html">Container</A>
</TD>
<TD VAlign=top>
Const iterator used to iterate through an <tt>slist</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>iterator begin()</tt>
</TD>
<TD VAlign=top>
<A href="Container.html">Container</A>
</TD>
<TD VAlign=top>
Returns an <tt>iterator</tt> pointing to the beginning of the <tt>slist</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>iterator end()</tt>
</TD>
<TD VAlign=top>
<A href="Container.html">Container</A>
</TD>
<TD VAlign=top>
Returns an <tt>iterator</tt> pointing to the end of the <tt>slist</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>const_iterator begin() const</tt>
</TD>
<TD VAlign=top>
<A href="Container.html">Container</A>
</TD>
<TD VAlign=top>
Returns a <tt>const_iterator</tt> pointing to the beginning of the <tt>slist</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>const_iterator end() const</tt>
</TD>
<TD VAlign=top>
<A href="Container.html">Container</A>
</TD>
<TD VAlign=top>
Returns a <tt>const_iterator</tt> pointing to the end of the <tt>slist</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>size_type size() const</tt>
</TD>
<TD VAlign=top>
<A href="Container.html">Container</A>
</TD>
<TD VAlign=top>
Returns the size of the <tt>slist</tt>. Note: you should not assume that
this function is constant time. It is permitted to be <i>O(N</i>),
where <i>N</i> is the number of elements in the <tt>slist</tt>. If you wish to
test whether an <tt>slist</tt> is empty, you should write <tt>L.empty()</tt> rather
than <tt>L.size() == 0</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>size_type max_size() const</tt>
</TD>
<TD VAlign=top>
<A href="Container.html">Container</A>
</TD>
<TD VAlign=top>
Returns the largest possible size of the <tt>slist</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>bool empty() const</tt>
</TD>
<TD VAlign=top>
<A href="Container.html">Container</A>
</TD>
<TD VAlign=top>
<tt>true</tt> if the <tt>slist</tt>'s size is <tt>0</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>slist()</tt>
</TD>
<TD VAlign=top>
<A href="Container.html">Container</A>
</TD>
<TD VAlign=top>
Creates an empty slist.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>slist(size_type n)</tt>
</TD>
<TD VAlign=top>
<A href="Sequence.html">Sequence</A>
</TD>
<TD VAlign=top>
Creates an <tt>slist</tt> with <tt>n</tt> elements, each of which is a copy of <tt>T()</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>slist(size_type n, const T& t)</tt>
</TD>
<TD VAlign=top>
<A href="Sequence.html">Sequence</A>
</TD>
<TD VAlign=top>
Creates an slist with <tt>n</tt> copies of <tt>t</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>slist(const slist&)</tt>
</TD>
<TD VAlign=top>
<A href="Container.html">Container</A>
</TD>
<TD VAlign=top>
The copy constructor.
</TD>
</TR>
<TR>
<TD VAlign=top>
<pre>
template <class InputIterator>
slist(InputIterator f, InputIterator l)
<A href="#3">[3]</A>
</pre>
</TD>
<TD VAlign=top>
<A href="Sequence.html">Sequence</A>
</TD>
<TD VAlign=top>
Creates an <tt>slist</tt> with a copy of a range.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>~slist()</tt>
</TD>
<TD VAlign=top>
<A href="Container.html">Container</A>
</TD>
<TD VAlign=top>
The destructor.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>slist& operator=(const slist&)</tt>
</TD>
<TD VAlign=top>
<A href="Container.html">Container</A>
</TD>
<TD VAlign=top>
The assignment operator
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>void swap(slist&)</tt>
</TD>
<TD VAlign=top>
<A href="Container.html">Container</A>
</TD>
<TD VAlign=top>
Swaps the contents of two slists.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>reference front()</tt>
</TD>
<TD VAlign=top>
<A href="FrontInsertionSequence.html">Front Insertion Sequence</A>
</TD>
<TD VAlign=top>
Returns the first element.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>const_reference front() const</tt>
</TD>
<TD VAlign=top>
<A href="FrontInsertionSequence.html">Front Insertion Sequence</A>
</TD>
<TD VAlign=top>
Returns the first element.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>void push_front(const T&)</tt>
</TD>
<TD VAlign=top>
<A href="FrontInsertionSequence.html">Front Insertion Sequence</A>
</TD>
<TD VAlign=top>
Inserts a new element at the beginning.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>void pop_front()</tt>
</TD>
<TD VAlign=top>
<A href="FrontInsertionSequence.html">Front Insertion Sequence</A>
</TD>
<TD VAlign=top>
Removes the first element.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>iterator previous(iterator pos)</tt>
</TD>
<TD VAlign=top>
<tt>slist</tt>
</TD>
<TD VAlign=top>
See below
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>const_iterator previous(const_iterator pos)</tt>
</TD>
<TD VAlign=top>
<tt>slist</tt>
</TD>
<TD VAlign=top>
See below
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>iterator insert(iterator pos, const T& x)</tt>
</TD>
<TD VAlign=top>
<A href="Sequence.html">Sequence</A>
</TD>
<TD VAlign=top>
Inserts <tt>x</tt> before <tt>pos</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<pre>
template<class InputIterator>
void insert(iterator pos, InputIterator f, InputIterator l)
<A href="#3">[3]</A>
</pre>
</TD>
<TD VAlign=top>
<A href="Sequence.html">Sequence</A>
</TD>
<TD VAlign=top>
Inserts the range <tt>[first, last)</tt> before <tt>pos</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<pre>
void insert(iterator pos,
size_type n, const value_type& x)
</pre>
</TD>
<TD VAlign=top>
<A href="Sequence.html">Sequence</A>
</TD>
<TD VAlign=top>
Inserts <tt>n</tt> copies of <tt>x</tt> before <tt>pos</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>iterator erase(iterator pos)</tt>
</TD>
<TD VAlign=top>
<A href="Sequence.html">Sequence</A>
</TD>
<TD VAlign=top>
Erases the element at position <tt>pos</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>iterator erase(iterator first, iterator last)</tt>
</TD>
<TD VAlign=top>
<A href="Sequence.html">Sequence</A>
</TD>
<TD VAlign=top>
Erases the range <tt>[first, last)</tt>
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>void clear()</tt>
</TD>
<TD VAlign=top>
<A href="Sequence.html">Sequence</A>
</TD>
<TD VAlign=top>
Erases all of the elements.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>void resize(n, t = T())</tt>
</TD>
<TD VAlign=top>
<A href="Sequence.html">Sequence</A>
</TD>
<TD VAlign=top>
Inserts or erases elements at the end such that the size becomes <tt>n</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>iterator insert_after(iterator pos)</tt>
</TD>
<TD VAlign=top>
<tt>slist</tt>
</TD>
<TD VAlign=top>
See below.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>iterator insert_after(iterator pos, const value_type& x)</tt>
</TD>
<TD VAlign=top>
<tt>slist</tt>
</TD>
<TD VAlign=top>
See below.
</TD>
</TR>
<TR>
<TD VAlign=top>
<pre>
template<class InputIterator>
void insert_after(iterator pos,
InputIterator f, InputIterator l)
</pre>
</TD>
<TD VAlign=top>
<tt>slist</tt>
</TD>
<TD VAlign=top>
See below.
</TD>
</TR>
<TR>
<TD VAlign=top>
<pre>
void insert_after(iterator pos,
size_type n, const value_type& x)
</pre>
</TD>
<TD VAlign=top>
<tt>slist</tt>
</TD>
<TD VAlign=top>
See below.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>iterator erase_after(iterator pos)</tt>
</TD>
<TD VAlign=top>
<tt>slist</tt>
</TD>
<TD VAlign=top>
See below.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>iterator erase_after(iterator before_first, iterator last)</tt>
</TD>
<TD VAlign=top>
<tt>slist</tt>
</TD>
<TD VAlign=top>
See below.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>void splice(iterator position, slist& L)</tt>
</TD>
<TD VAlign=top>
<tt>slist</tt>
</TD>
<TD VAlign=top>
See below.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>void splice(iterator position, slist& L, iterator i)</tt>
</TD>
<TD VAlign=top>
<tt>slist</tt>
</TD>
<TD VAlign=top>
See below.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>void splice(iterator position, slist& L, iterator f, iterator l)</tt>
</TD>
<TD VAlign=top>
<tt>slist</tt>
</TD>
<TD VAlign=top>
See below.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>void splice_after(iterator pos, iterator prev)</tt>
</TD>
<TD VAlign=top>
<tt>slist</tt>
</TD>
<TD VAlign=top>
See below.
</TD>
</TR>
<TR>
<TD VAlign=top>
<pre>
void splice_after(iterator pos,
iterator before_first,
iterator before_last)
</pre>
</TD>
<TD VAlign=top>
<tt>slist</tt>
</TD>
<TD VAlign=top>
See below.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>void remove(const T& value)</tt>
</TD>
<TD VAlign=top>
<tt>slist</tt>
</TD>
<TD VAlign=top>
See below.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>void unique()</tt>
</TD>
<TD VAlign=top>
<tt>slist</tt>
</TD>
<TD VAlign=top>
See below.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>void merge(slist& L)</tt>
</TD>
<TD VAlign=top>
<tt>slist</tt>
</TD>
<TD VAlign=top>
See below.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>void sort()</tt>
</TD>
<TD VAlign=top>
<tt>slist</tt>
</TD>
<TD VAlign=top>
See below.
</TD>
</TR>
<TR>
<TD VAlign=top>
<pre>
bool operator==(const slist&,
const slist&)
</pre>
</TD>
<TD VAlign=top>
<A href="ForwardContainer.html">Forward Container</A>
</TD>
<TD VAlign=top>
Tests two slists for equality. This is a global function, not
a member function.
</TD>
</TR>
<TR>
<TD VAlign=top>
<pre>
bool operator<(const slist&,
const slist&)
</pre>
</TD>
<TD VAlign=top>
<A href="ForwardContainer.html">Forward Container</A>
</TD>
<TD VAlign=top>
Lexicographical comparison. This is a global function, not
a member function.
</TD>
</tr>
</table>
<h3>New members</h3>
These members are not defined in the
<A href="FrontInsertionSequence.html">Front Insertion Sequence</A> requirements, but are specific to <tt>slist</tt>:
<Table border>
<TR>
<TH>
Function
</TH>
<TH>
Description
</TH>
</TR>
<TR>
<TD VAlign=top>
<tt>iterator previous(iterator pos)</tt>
</TD>
<TD VAlign=top>
<tt>pos</tt> must be a valid iterator in <tt>*this</tt>. The return value is
an iterator <tt>prev</tt> such that <tt>++prev == pos</tt>. Complexity:
linear in the number of iterators in the range <tt>[begin(), pos)</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>const_iterator previous(const_iterator pos)</tt>
</TD>
<TD VAlign=top>
<tt>pos</tt> must be a valid iterator in <tt>*this</tt>. The return value is
an iterator <tt>prev</tt> such that <tt>++prev == pos</tt>. Complexity:
linear in the number of iterators in the range <tt>[begin(), pos)</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>iterator insert_after(iterator pos)</tt>
</TD>
<TD VAlign=top>
<tt>pos</tt> must be a dereferenceable iterator in <tt>*this</tt>. (That is,
<tt>pos</tt> may not be <tt>end()</tt>.) Inserts a copy of <tt>T()</tt> immediately
<i>following</i> <tt>pos</tt>. The return value is an iterator that points
to the new element. Complexity: constant time.
</TD>
</TR>
<TR>
<TD VAlign=top>
<pre>
iterator insert_after(iterator pos,
const value_type& x)
</pre>
</TD>
<TD VAlign=top>
<tt>pos</tt> must be a dereferenceable iterator in <tt>*this</tt>. (That is,
<tt>pos</tt> may not be <tt>end()</tt>.) Inserts a copy of <tt>x</tt> immediately
<i>following</i> <tt>pos</tt>. The return value is an iterator that points
to the new element. Complexity: constant time.
</TD>
</TR>
<TR>
<TD VAlign=top>
<pre>
template<class InputIterator>
void insert_after(iterator pos,
InputIterator f, InputIterator l)
</pre>
</TD>
<TD VAlign=top>
Inserts elements from the range <tt>[f, l)</tt> immediately
<i>following</i> <tt>pos</tt>. Complexity: linear in <tt>last - first</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<pre>
void insert_after(iterator pos,
size_type n, const value_type& x)
</pre>
</TD>
<TD VAlign=top>
Inserts <tt>n</tt> copies of <tt>x</tt> immediately <i>following</i> <tt>pos</tt>.
Complexity: linear in <tt>n</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>iterator erase_after(iterator pos)</tt>
</TD>
<TD VAlign=top>
Erases the element pointed to by the iterator <i>following</i> <tt>pos</tt>.
Complexity: constant time.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>iterator erase_after(iterator before_first, iterator last)</tt>
</TD>
<TD VAlign=top>
Erases all elements in the range <tt>[before_first + 1, last)</tt>.
Complexity: linear in <tt>last - (before_first + 1)</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<pre>
void splice(iterator position,
slist<T, Alloc>& x);
</pre>
</TD>
<TD VAlign=top>
<tt>position</tt> must be a valid iterator in <tt>*this</tt>, and <tt>x</tt> must be an slist
that is distinct from <tt>*this</tt>. (That is, it is required that
<tt>&x != this</tt>.) All of the elements of <tt>x</tt> are inserted before
<tt>position</tt> and removed from <tt>x</tt>. All iterators remain valid,
including iterators that point to elements of <tt>x</tt>. <A href="#4">[4]</A> Complexity:
proportional to <tt>c1 (position - begin()) + c2(x.size())</tt>, where <tt>c1</tt>
and <tt>c2</tt> are unknown constants.
</TD>
</TR>
<TR>
<TD VAlign=top>
<pre>
void splice(iterator position,
slist<T, Alloc>& x,
iterator i);
</pre>
</TD>
<TD VAlign=top>
<tt>position</tt> must be a valid iterator in <tt>*this</tt>, and <tt>i</tt> must be a
dereferenceable iterator in <tt>x</tt>. <tt>Splice</tt> moves the element
pointed to by <tt>i</tt> from <tt>x</tt> to <tt>*this</tt>, inserting it before
<tt>position</tt>. All iterators remain valid, including iterators that point
to elements of <tt>x</tt>. <A href="#4">[4]</A> If <tt>position == i</tt> or <tt>position == ++i</tt>,
this function is a null operation. Complexity: proportional to
<tt>c1 (position - begin()) + c2 (i - x.begin())</tt>, where <tt>c1</tt> and
<tt>c2</tt> are unknown constants.
</TD>
</TR>
<TR>
<TD VAlign=top>
<pre>
void splice(iterator position,
slist<T, Alloc>& x,
iterator f, iterator l);
</pre>
</TD>
<TD VAlign=top>
<tt>position</tt> must be a valid iterator in <tt>*this</tt>, and <tt>[first, last)</tt>
must be a valid range in <tt>x</tt>. <tt>position</tt> may not be an iterator
in the range <tt>[first, last)</tt>. <tt>Splice</tt> moves the elements
in <tt>[first, last)</tt> from <tt>x</tt> to <tt>*this</tt>, inserting them before
<tt>position</tt>. All iterators remain valid, including iterators that
point to elements of <tt>x</tt>. <A href="#4">[4]</A> Complexity: proportional to
<tt>c1 (position - begin()) + c2 (f - x.begin()) + c3 (l - f)</tt>,
where <tt>c1</tt>, <tt>c2</tt>, and <tt>c3</tt> are unknown constants.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>void remove(const T& val);</tt>
</TD>
<TD VAlign=top>
Removes all elements that compare equal to <tt>val</tt>. The relative order
of elements that are not removed is unchanged, and iterators to
elements that are not removed remain valid. This function is
linear time: it performs exactly <tt>size()</tt> comparisons for equality.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>void splice_after(iterator pos, iterator prev)</tt>
</TD>
<TD VAlign=top>
<tt>pos</tt> must be a dereferenceable iterator in <tt>*this</tt>, and <tt>prev</tt>
must be a dereferenceable iterator either in <tt>*this</tt> or in some
other <tt>slist</tt>. (Note: "dereferenceable iterator" implies that neither
<tt>pos</tt> nor <tt>prev</tt> may be an off-the-end iterator.) Moves the element
<i>following</i> <tt>prev</tt> to <tt>*this</tt>, inserting it immediately <i>after</i>
<tt>pos</tt>. Complexity: constant time.
</TD>
</TR>
<TR>
<TD VAlign=top>
<pre>
void splice_after(iterator pos,
iterator before_first,
iterator before_last)
</pre>
</TD>
<TD VAlign=top>
<tt>pos</tt> must be a dereferenceable iterator in <tt>*this</tt>, and
<tt>before_first</tt> and <tt>before_last</tt> must be dereferenceable iterators
either in <tt>*this</tt> or in some other <tt>slist</tt>. (Note:
"dereferenceable iterator" implies that none of these iterators may
be off-the-end iterators.) Moves the elements in the range
<tt>[before_first + 1, before_last + 1)</tt> to <tt>*this</tt>, inserting
them immediately <i>after</i> <tt>pos</tt>. Complexity: constant time.
</TD>
</TR>
<TR>
<TD VAlign=top>
<pre>
template<class <A href="Predicate.html">Predicate</A>>
void remove_if(<A href="Predicate.html">Predicate</A> p);
<A href="#5">[5]</A>
</pre>
</TD>
<TD VAlign=top>
Removes all elements <tt>*i</tt> such that <tt>p(*i)</tt> is true. The relative
order of elements that are not removed is unchanged, and iterators to
elements that are not removed remain valid. This function is linear
time: it performs exactly <tt>size()</tt> applications of <tt>p</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>void unique();</tt>
</TD>
<TD VAlign=top>
Removes all but the first element in every consecutive group of
equal elements. The relative order
of elements that are not removed is unchanged, and iterators to
elements that are not removed remain valid. This function is
linear time: it performs exactly <tt>size() - 1</tt> comparisons for equality.
</TD>
</TR>
<TR>
<TD VAlign=top>
<pre>
template<class <A href="BinaryPredicate.html">BinaryPredicate</A>>
void unique(<A href="BinaryPredicate.html">BinaryPredicate</A> p);
<A href="#5">[5]</A>
</pre>
</TD>
<TD VAlign=top>
Removes all but the first element in every consecutive group of
equivalent elements, where two elements <tt>*i</tt> and <tt>*j</tt> are considered
equivalent if <tt>p(*i, *j)</tt> is true. The relative order
of elements that are not removed is unchanged, and iterators to
elements that are not removed remain valid. This function is
linear time: it performs exactly <tt>size() - 1</tt> comparisons for
equality.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>void merge(slist<T, Alloc>& x);</tt>
</TD>
<TD VAlign=top>
Both <tt>*this</tt> and <tt>x</tt> must be sorted according to <tt>operator<</tt>, and
they must be distinct.
(That is, it is required that <tt>&x != this</tt>.) This function removes
all of <tt>x</tt>'s elements and inserts them in order into <tt>*this</tt>. The merge is
stable; that is, if an element from <tt>*this</tt> is equivalent to one from
<tt>x</tt>, then the element from <tt>*this</tt> will precede the one from <tt>x</tt>.
All iterators to elements in <tt>*this</tt> and <tt>x</tt> remain valid.
This function is linear time: it performs at most <tt>size() + x.size()
- 1</tt> comparisons.
</TD>
</TR>
<TR>
<TD VAlign=top>
<pre>
template<class <A href="BinaryPredicate.html">BinaryPredicate</A>>
void merge(slist<T, Alloc>& x,
BinaryPredicate Comp);
<A href="#5">[5]</A>
</pre>
</TD>
<TD VAlign=top>
<tt>Comp</tt> must be a comparison function that induces a strict weak
ordering (as defined in the <A href="LessThanComparable.html">LessThan Comparable</A> requirements)
on objects of type <tt>T</tt>, and both <tt>*this</tt> and <tt>x</tt> must be sorted
according to that ordering. The slists <tt>x</tt> and <tt>*this</tt> must be
distinct. (That is, it is required that <tt>&x != this</tt>.)
This function removes
all of <tt>x</tt>'s elements and inserts them in order into <tt>*this</tt>. The merge is
stable; that is, if an element from <tt>*this</tt> is equivalent to one from
<tt>x</tt>, then the element from <tt>*this</tt> will precede the one from <tt>x</tt>.
All iterators to elements in <tt>*this</tt> and <tt>x</tt> remain valid.
This function is linear time: it performs at most <tt>size() + x.size()
- 1</tt> applications of <tt>Comp</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>void reverse();</tt>
</TD>
<TD VAlign=top>
Reverses the order of elements in the slist. All iterators remain
valid and continue to point to the same elements. <A href="#6">[6]</A> This function
is linear time.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>void sort();</tt>
</TD>
<TD VAlign=top>
Sorts <tt>*this</tt> according to <tt>operator<</tt>. The sort is stable, that is,
the relative order of equivalent elements is preserved.
All iterators remain
valid and continue to point to the same elements. <A href="#7">[7]</A> The number
of comparisons is approximately <tt>N log N</tt>, where <tt>N</tt> is the <tt>slist</tt>'s
size.
</TD>
</TR>
<TR>
<TD VAlign=top>
<pre>
template<class <A href="BinaryPredicate.html">BinaryPredicate</A>>
void sort(BinaryPredicate comp);
<A href="#5">[5]</A>
</pre>
</TD>
<TD VAlign=top>
<tt>Comp</tt> must be a comparison function that induces a strict weak
ordering (as defined in the <A href="LessThanComparable.html">LessThan Comparable</A> requirements)
on objects of type <tt>T</tt>. This function sorts the slist
<tt>*this</tt> according to <tt>Comp</tt>. The sort is stable, that is,
the relative order of equivalent elements is preserved.
All iterators remain
valid and continue to point to the same elements. <A href="#7">[7]</A> The number
of comparisons is approximately <tt>N log N</tt>, where <tt>N</tt> is the <tt>slist</tt>'s
size.
</TD>
</tr>
</table>
<h3>Notes</h3>
<P><A name="1">[1]</A>
The lists in such languages as Common Lisp, Scheme, and ML are singly
linked lists. In some programming languages, almost all data
structures are represented as singly linked lists.
<P><A name="2">[2]</A>
A comparison with <tt><A href="Vector.html">vector</A></tt> is
instructive. Suppose that <tt>i</tt> is a valid
<tt><A href="Vector.html">vector</A><T>::iterator</tt>. If an element
is inserted or removed in a position that precedes <tt>i</tt>, then
this operation will either result in <tt>i</tt> pointing to a
different element than it did before, or else it will invalidate
<tt>i</tt> entirely. (A
<tt><A href="Vector.html">vector</A><T>::iterator</tt> will be
invalidated, for example, if an insertion requires a reallocation.)
However, suppose that <tt>i</tt> and <tt>j</tt> are both iterators
into a <A href="Vector.html">vector</A>, and there exists some integer
<tt>n</tt> such that <tt>i == j + n</tt>. In that case, even if
elements are inserted into the vector and <tt>i</tt> and <tt>j</tt>
point to different elements, the relation between the two iterators
will still hold. An <tt>slist</tt> is exactly the opposite: iterators
will not be invalidated, and will not be made to point to different
elements, but, for <tt>slist</tt> iterators, the predecessor/successor
relationship is not invariant.
<P><A name="3">[3]</A>
This member function relies on <i>member template</i> functions, which
at present (early 1998) are not supported by all compilers. If your
compiler supports member templates, you can call this function with
any type of <A href="InputIterator.html">input iterator</A>. If your
compiler does not yet support member templates, though, then the
arguments must either be of type <tt>const value_type*</tt> or of type
<tt>slist::const_iterator</tt>.
<P><A name="4">[4]</A>
A similar property holds for all versions of <tt>insert()</tt> and
<tt>erase()</tt>. <tt>Slist<T, Alloc>::insert()</tt> never
invalidates any iterators, and <tt>slist<T, Alloc>::erase()</tt>
only invalidates iterators pointing to the elements that are actually
being erased.
<P><A name="5">[5]</A>
This member function relies on <i>member template</i> functions, which
at present (early 1998) are not supported by all compilers. You can
only use this member function if your compiler supports member
templates.
<P><A name="6">[6]</A>
The <tt><A href="reverse.html">reverse</A></tt> algorithm works only
for <A href="BidirectionalIterator.html">bidirectional iterators</A>.
Even if <tt><A href="reverse.html">reverse</A></tt> were extended to
work with <A href="ForwardIterator.html">forward iterators</A>,
however, it would still be useful to have the <tt>reverse</tt> member
function: it has different iterator invalidation semantics. That is,
the <tt>reverse</tt> member function preserves the value that each
iterator points to. Note also that the algorithm
<tt><A href="reverse.html">reverse</A>(L.begin(), L.end())</tt> uses
<tt>T</tt>'s assignment operator, but the member function
<tt>L.reverse()</tt> does not.
<P><A name="7">[7]</A>
The <tt><A href="sort.html">sort</A></tt> algorithm works only for
<A href="RandomAccessIterator.html">random access iterators</A>. In
principle, however, it would be possible to write a sort algorithm
that also accepted
<A href="ForwardIterator.html">forward iterators</A>. Even if there were such a version
of <tt><A href="sort.html">sort</A></tt>, it would still be useful for
<tt>slist</tt> to have a <tt>sort</tt> member function. That is,
<tt>sort</tt> is provided as a member function not only for the sake
of efficiency, but also because of the property that it preserves the
values that list iterators point to.
<h3>See also</h3>
<A href="BidirectionalIterator.html">Bidirectional Iterator</A>,
<A href="ReversibleContainer.html">Reversible Container</A>,
<A href="Sequence.html">Sequence</A>,
<tt><A href="List.html">list</A></tt>,
<tt><A href="Vector.html">vector</A></tt>
<!--start footer-->
<HR SIZE="6">
<A href="http://www.sgi.com/"><IMG SRC="surf.gif" HEIGHT="54" WIDTH="54"
ALT="[Silicon Surf]"></A>
<A HREF="index.html"><IMG SRC="stl_home.gif"
HEIGHT="54" WIDTH="54" ALT="[STL Home]"></A>
<BR>
<FONT SIZE="-2">
<A href="http://www.sgi.com/Misc/sgi_info.html" TARGET="_top">Copyright ©
1999 Silicon Graphics, Inc.</A> All Rights Reserved.</FONT>
<FONT SIZE="-3"><a href="http://www.sgi.com/Misc/external.list.html" TARGET="_top">TrademarkInformation</A>
</FONT>
<P>
</BODY>
</HTML>
|