{\rtf1\ansi \deff8\deflang1033{\fonttbl{\f0\froman\fcharset0\fprq2 Tms Rmn;}{\f1\froman\fcharset2\fprq2 Symbol;}{\f2\fswiss\fcharset0\fprq2 Helv;}{\f3\fmodern\fcharset0\fprq1 Courier;} {\f4\froman\fcharset0\fprq2 Times New Roman;}{\f5\fswiss\fcharset0\fprq2 Arial;}{\f6\froman\fcharset0\fprq2 MS Serif;}{\f7\fswiss\fcharset0\fprq2 MS Sans Serif;}{\f8\froman\fcharset0\fprq2 Times;}{\f9\fswiss\fcharset0\fprq2 Helvetica;} {\f10\fswiss\fcharset0\fprq2 System;}{\f11\fmodern\fcharset0\fprq1 Courier New;}{\f12\froman\fcharset0\fprq2 New York;}{\f13\fswiss\fcharset0\fprq2 Geneva;}{\f14\fswiss\fcharset0\fprq2 AvantGarde;}{\f15\froman\fcharset0\fprq2 ITC Bookman;} {\f16\fswiss\fcharset0\fprq2 Helvetica-Narrow;}{\f17\froman\fcharset0\fprq2 NewCenturySchlbk;}{\f18\froman\fcharset0\fprq2 Palatino;}{\f19\froman\fcharset0\fprq2 ZapfChancery;}{\f20\fdecor\fcharset2\fprq2 ZapfDingbats;} {\f21\fmodern\fcharset0\fprq1 Lucida Console;}{\f22\fnil\fcharset2\fprq2 Wingdings;}{\f23\froman\fcharset2\fprq2 MT Extra;}{\f24\fmodern\fcharset2\fprq1 MS LineDraw;}{\f25\fdecor\fcharset0\fprq2 Algerian;} {\f26\fswiss\fcharset0\fprq2 Arial Rounded MT Bold;}{\f27\fdecor\fcharset0\fprq2 Bauhaus 93;}{\f28\froman\fcharset0\fprq2 Bookman Old Style;}{\f29\fdecor\fcharset0\fprq2 Braggadocio;}{\f30\fswiss\fcharset0\fprq2 Britannic Bold;} {\f31\fscript\fcharset0\fprq2 Brush Script MT;}{\f32\fdecor\fcharset0\fprq2 Colonna MT;}{\f33\fdecor\fcharset0\fprq2 Desdemona;}{\f34\froman\fcharset0\fprq2 Footlight MT Light;}{\f35\fswiss\fcharset0\fprq2 Century Gothic;} {\f36\fscript\fcharset0\fprq2 Gradl;}{\f37\fswiss\fcharset0\fprq2 Impact;}{\f38\fdecor\fcharset0\fprq2 Kino MT;}{\f39\froman\fcharset0\fprq2 Wide Latin;}{\f40\fscript\fcharset0\fprq2 Matura MT Script Capitals;}{\f41\fscript\fcharset0\fprq2 Mistral;} {\f42\fdecor\fcharset0\fprq2 Playbill;}{\f43\fdecor\fcharset0\fprq2 Stencil;}{\f44\fscript\fcharset0\fprq2 Vivaldi;}{\f45\froman\fcharset255\fprq2 Roman;}{\f46\fscript\fcharset255\fprq2 Script;}{\f47\fmodern\fcharset255\fprq2 Modern;} {\f48\fswiss\fcharset0\fprq1 MS Dialog;}}{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;\red0\green255\blue0;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;\red255\green255\blue255;\red0\green0\blue128; \red0\green128\blue128;\red0\green128\blue0;\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;\red128\green128\blue128;\red192\green192\blue192;}{\stylesheet{\nowidctlpar \f8 \snext0 Normal;}{\*\cs10 \additive Default Paragraph Font;}{ \s15\sl260\slmult0\nowidctlpar \f8 \sbasedon0\snext15 Abstract;}{\s16\qc\nowidctlpar \f8 \sbasedon0\snext16 Author;}{\s17\qj\nowidctlpar \f8 \sbasedon0\snext17 body;}{\s18\fi-173\li1080\sl260\slmult0\nowidctlpar\tx1080\tx1253 \f8 \sbasedon0\snext18 bullet1;}{\s19\fi-230\li850\sl260\slmult0\nowidctlpar\tx850 \f8 \sbasedon0\snext19 bullet2;}{\s20\qc\nowidctlpar \f8 \sbasedon0\snext20 cbody;}{\s21\nowidctlpar \f8 \sbasedon0\snext21 CellBody;}{\s22\nowidctlpar \f8 \sbasedon0\snext22 Date;}{ \s23\qj\nowidctlpar \f8 \sbasedon0\snext23 ebody;}{\s24\qj\li1080\nowidctlpar \f8 \sbasedon0\snext24 Footnote;}{\s25\fi-230\li1210\sl260\slmult0\nowidctlpar\tx1210\tqr\tx1253\tx1440 \f8 \sbasedon0\snext25 footnote;}{\s26\qc\nowidctlpar \f8 \sbasedon0\snext26 heading;}{\s27\li1080\sl260\slmult0\nowidctlpar\tx1080\tx1167 \f8 \sbasedon0\snext27 indent1;}{\s28\li850\sl260\slmult0\nowidctlpar\tx850 \f8 \sbasedon0\snext28 indent2;}{\s29\fi-360\li1080\sl260\slmult0 \nowidctlpar\tx1080\tqr\tx1138\tx1440 \f8 \sbasedon0\snext29 number1;}{\s30\fi-230\li1210\sl260\slmult0\nowidctlpar \f8 \sbasedon0\snext30 number1Start;}{\s31\nowidctlpar \f8 \sbasedon0\snext31 Organization;}{ \s32\fi-1440\li720\nowidctlpar\tx0\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200 \f8 \sbasedon0\snext32 program;}{\s33\fi-230\li1210\sl260\slmult0\nowidctlpar\tx1210\tx1440 \f8 \sbasedon0\snext33 reference;}{\s34\nowidctlpar\tx1167 \f8 \sbasedon0\snext34 section;}{\s35\qj\fi-532\li908\nowidctlpar\tx908\tqr\tldot\tx7920 \f8 \sbasedon0\snext35 sectionTOC;}{\s36\sl260\slmult0\nowidctlpar \f8 \sbasedon0\snext36 subheading;}{\s37\sl260\slmult0\nowidctlpar \f8 \sbasedon0\snext37 subsection;}{\s38\qj\fi-548\li360\nowidctlpar\tx360\tqr\tldot\tx7920 \f8 \sbasedon0\snext38 subsectionTOC;}{\s39\sl260\slmult0\nowidctlpar \f8 \sbasedon0\snext39 subsubheading;}{\s40\sl260\slmult0\nowidctlpar \f8 \sbasedon0\snext40 subsubsection;}{ \s41\qj\fi-532\li172\nowidctlpar\tx172\tqr\tldot\tx7920 \f8 \sbasedon0\snext41 subsubsectionTOC;}{\s42\qc\sl240\slmult0\nowidctlpar\tqr\tx10080 \f8 \sbasedon0\snext42 Title;}{\s43\sl240\slmult0\nowidctlpar\tqr\tx10080 \f8 \sbasedon0\snext43 TRnumber;}{ \s44\nowidctlpar\tqc\tx4320\tqr\tx8640 \f8 \sbasedon0\snext44 footer;}{\*\cs45 \additive\sbasedon10 page number;}{\s46\sb120\sa120\nowidctlpar\tqr\tldot\tx8812 \b\caps\f4\fs20 \sbasedon0\snext0 toc 1;}{\s47\nowidctlpar\tqr\tldot\tx8812 \scaps\f4\fs20 \sbasedon0\snext0 toc 2;}{\s48\li240\nowidctlpar\tqr\tldot\tx8812 \i\f4\fs20 \sbasedon0\snext0 toc 3;}{\s49\li480\nowidctlpar\tqr\tldot\tx8812 \f4\fs18 \sbasedon0\snext0 toc 4;}{\s50\li720\nowidctlpar\tqr\tldot\tx8812 \f4\fs18 \sbasedon0\snext0 toc 5;}{ \s51\li960\nowidctlpar\tqr\tldot\tx8812 \f4\fs18 \sbasedon0\snext0 toc 6;}{\s52\li1200\nowidctlpar\tqr\tldot\tx8812 \f4\fs18 \sbasedon0\snext0 toc 7;}{\s53\li1440\nowidctlpar\tqr\tldot\tx8812 \f4\fs18 \sbasedon0\snext0 toc 8;}{ \s54\li1680\nowidctlpar\tqr\tldot\tx8812 \f4\fs18 \sbasedon0\snext0 toc 9;}}{\*\revtbl {Unknown;}}{\info{\title The Standard Template Library}{\author Kerry Loynd}{\operator Kerry Loynd}{\creatim\yr1995\mo7\dy13\hr16\min3}{\revtim\yr1995\mo7\dy13\hr16\min48}{\version5} {\edmins38}{\nofpages0}{\nofwords0}{\nofchars0}{\vern49221}}\margl1440\margr1988 \widowctrl\ftnbj\aenddoc\hyphcaps0 \fet0\sectd \sbknone\pgnrestart\linex0 {\footer \pard\plain \s44\nowidctlpar\tqc\tx4320\tqr\tx8640\pvpara\phmrg\posxr\posy0 \f8 {\field{\*\fldinst {\cs45 PAGE }}{\fldrslt {\cs45 81}}}{\cs45 \par }\pard \s44\ri360\nowidctlpar\tqc\tx4320\tqr\tx8640 \par }{\*\pnseclvl1\pnucrm\pnstart1\pnindent720\pnhang{\pntxta .}}{\*\pnseclvl2\pnucltr\pnstart1\pnindent720\pnhang{\pntxta .}}{\*\pnseclvl3\pndec\pnstart1\pnindent720\pnhang{\pntxta .}}{\*\pnseclvl4\pnlcltr\pnstart1\pnindent720\pnhang{\pntxta )}}{\*\pnseclvl5 \pndec\pnstart1\pnindent720\pnhang{\pntxtb (}{\pntxta )}}{\*\pnseclvl6\pnlcltr\pnstart1\pnindent720\pnhang{\pntxtb (}{\pntxta )}}{\*\pnseclvl7\pnlcrm\pnstart1\pnindent720\pnhang{\pntxtb (}{\pntxta )}}{\*\pnseclvl8\pnlcltr\pnstart1\pnindent720\pnhang {\pntxtb (}{\pntxta )}}{\*\pnseclvl9\pnlcrm\pnstart1\pnindent720\pnhang{\pntxtb (}{\pntxta )}}\pard\plain \s42\qc\ri-548\sb140\nowidctlpar \f8 {\b\f9\fs36\cf1 The Standard Template Library \par }\pard \s42\qc\ri-548\sb140\nowidctlpar {\b\f9\fs36\cf1 \par }\pard\plain \s16\qc\ri-548\sb200\sl280\slmult0\nowidctlpar \f8 {\i\fs28\cf1 Alexander Stepanov}{\b\fs28\cf1 \par }\pard \s16\qc\ri-548\sb200\sl280\slmult0\nowidctlpar {\b\fs28\cf1 \par }\pard\plain \s43\qc\ri-548\sb20\nowidctlpar \f8 {\i\cf1 Silicon Graphics Inc.}{\b\cf1 \par }\pard \s43\qc\ri-548\sb20\nowidctlpar {\i\cf1 2011 N. Shoreline Blvd.}{\b\cf1 \par }{\i\cf1 Mt. View, CA 94043}{\b\cf1 \par }{\i\cf1 stepanov@mti.sgi.com}{\b\cf1 \par }\pard \s43\qc\ri-548\sb20\nowidctlpar {\b\cf1 \par }\pard\plain \s16\qc\ri-548\sb200\sl280\slmult0\nowidctlpar \f8 {\i\fs28\cf1 Meng Lee}{\b\fs28\cf1 \par }\pard \s16\qc\ri-548\sb200\sl280\slmult0\nowidctlpar {\b\fs28\cf1 \par }\pard\plain \s43\qc\ri-548\sb20\nowidctlpar \f8 {\i\cf1 Hewlett-Packard Laboratories}{\b\cf1 \par }\pard \s43\qc\ri-548\sb20\nowidctlpar {\i\cf1 1501 Page Mill Road}{\b\cf1 \par }{\i\cf1 Palo Alto, CA 94304}{\b\cf1 \par }{\i\cf1 lee@hpl.hp.com}{\b\cf1 \par }\pard \s43\qc\ri-548\sb20\nowidctlpar {\b\cf1 \par \par \par \par \par \par \par \par \par }\pard\plain \s20\qc\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 July 7, 1995}{\b\f18\fs20\cf1 \par }\pard \s20\qc\ri-548\sb140\sl280\slmult0\nowidctlpar {\b\f18\fs20\cf1 \par \par \par \par \par \par \par \par \par \par \par \par \par \par }\pard \s20\qc\ri-548\sb140\sl280\slmult0\nowidctlpar {\b\f18\fs20\cf1 \par }\pard\plain \nowidctlpar \f8 \par \pard \nowidctlpar \par \pard\plain \s35\qj\fi-532\li532\sb120\sl280\slmult0\nowidctlpar\pvpg\phpg\posx2707\posy9720\absh2390\absw6811 \f8 {\f18\fs20\cf1 Copyright (c) 1994 Hewlett-Packard Company}{\b\f18\fs20\cf1 \par }\pard\plain \s17\qj\sb140\sl280\slmult0\nowidctlpar\pvpg\phpg\posx2707\posy9720\absh2390\absw6811 \f8 {\f18\fs20\cf1 Permission to use, copy, modify, distribute and sell this document for any purpose is hereby granted without fee,\~ provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation.}{\b\f18\fs20\cf1 \par }\pard\plain \s35\fi-532\li532\ri-548\sb120\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 \page }{\field\fldedit{\*\fldinst {\f18\fs20\cf1 TOC \\t "section,1,subsection,2,subsubsection,3" }}{\fldrslt \par \pard\plain \s46\sb120\sa120\nowidctlpar\tqr\tldot\tx8812 \b\caps\f4\fs20 {\cf1 1 Introduction}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285519 {\field{\*\fldinst PAGEREF _Toc330285519 }{\fldrslt 5}}}} \par \pard \s46\sb120\sa120\nowidctlpar\tqr\tldot\tx8812 {\cf1 2 Structure of the library}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285520 {\field{\*\fldinst PAGEREF _Toc330285520 }{\fldrslt 5}}}} \par {\cf1 3 Requirements}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285521 {\field{\*\fldinst PAGEREF _Toc330285521 }{\fldrslt 7}}}} \par {\cf1 4 Core components}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285522 {\field{\*\fldinst PAGEREF _Toc330285522 }{\fldrslt 7}}}} \par \pard\plain \s47\nowidctlpar\tqr\tldot\tx8812 \scaps\f4\fs20 {\b\cf1 4.1 Operators}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285523 {\field{\*\fldinst PAGEREF _Toc330285523 }{\fldrslt 7}}}} \par \pard \s47\nowidctlpar\tqr\tldot\tx8812 {\b\cf1 4.2 Pair}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285524 {\field{\*\fldinst PAGEREF _Toc330285524 }{\fldrslt 8}}}} \par \pard\plain \s46\sb120\sa120\nowidctlpar\tqr\tldot\tx8812 \b\caps\f4\fs20 {\cf1 5 Iterators}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285525 {\field{\*\fldinst PAGEREF _Toc330285525 }{\fldrslt 9}}}} \par \pard\plain \s47\nowidctlpar\tqr\tldot\tx8812 \scaps\f4\fs20 {\b\cf1 5.1 Input iterators}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285526 {\field{\*\fldinst PAGEREF _Toc330285526 }{\fldrslt 10}}}} \par \pard \s47\nowidctlpar\tqr\tldot\tx8812 {\b\cf1 5.2 Output iterators}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285527 {\field{\*\fldinst PAGEREF _Toc330285527 }{\fldrslt 10}}}} \par {\b\cf1 5.3 Forward iterators}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285528 {\field{\*\fldinst PAGEREF _Toc330285528 }{\fldrslt 11}}}} \par {\b\cf1 5.4 Bidirectional iterators}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285529 {\field{\*\fldinst PAGEREF _Toc330285529 }{\fldrslt 12}}}} \par {\b\cf1 5.5 Random access iterators}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285530 {\field{\*\fldinst PAGEREF _Toc330285530 }{\fldrslt 12}}}} \par {\b\cf1 5.6 Iterator tags}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285531 {\field{\*\fldinst PAGEREF _Toc330285531 }{\fldrslt 13}}}} \par \pard\plain \s48\li240\nowidctlpar\tqr\tldot\tx8812 \i\f4\fs20 {\cf1 5.6.1 Examples of using iterator tags}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285532 {\field{\*\fldinst PAGEREF _Toc330285532 }{\fldrslt 13}}}} \par \pard \s48\li240\nowidctlpar\tqr\tldot\tx8812 {\cf1 5.6.2 Library defined primitives}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285533 {\field{\*\fldinst PAGEREF _Toc330285533 }{\fldrslt 15}}}} \par \pard\plain \s47\nowidctlpar\tqr\tldot\tx8812 \scaps\f4\fs20 {\b\cf1 5.7 Iterator operations}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285534 {\field{\*\fldinst PAGEREF _Toc330285534 }{\fldrslt 17}}}} \par \pard\plain \s46\sb120\sa120\nowidctlpar\tqr\tldot\tx8812 \b\caps\f4\fs20 {\cf1 6 Function objects}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285535 {\field{\*\fldinst PAGEREF _Toc330285535 }{\fldrslt 18}}}} \par \pard\plain \s47\nowidctlpar\tqr\tldot\tx8812 \scaps\f4\fs20 {\b\cf1 6.1 Base}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285536 {\field{\*\fldinst PAGEREF _Toc330285536 }{\fldrslt 18}}}} \par \pard \s47\nowidctlpar\tqr\tldot\tx8812 {\b\cf1 6.2 Arithmetic operations}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285537 {\field{\*\fldinst PAGEREF _Toc330285537 }{\fldrslt 18}}}} \par {\b\cf1 6.3 Comparisons}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285538 {\field{\*\fldinst PAGEREF _Toc330285538 }{\fldrslt 19}}}} \par {\b\cf1 6.4 Logical operations}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285539 {\field{\*\fldinst PAGEREF _Toc330285539 }{\fldrslt 20}}}} \par \pard\plain \s46\sb120\sa120\nowidctlpar\tqr\tldot\tx8812 \b\caps\f4\fs20 {\cf1 7 Allocators}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285540 {\field{\*\fldinst PAGEREF _Toc330285540 }{\fldrslt 20}}}} \par \pard\plain \s47\nowidctlpar\tqr\tldot\tx8812 \scaps\f4\fs20 {\b\cf1 7.1 Allocator requirements}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285541 {\field{\*\fldinst PAGEREF _Toc330285541 }{\fldrslt 20}}}} \par \pard \s47\nowidctlpar\tqr\tldot\tx8812 {\b\cf1 7.2 The default allocator}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285542 {\field{\*\fldinst PAGEREF _Toc330285542 }{\fldrslt 21}}}} \par \pard\plain \s46\sb120\sa120\nowidctlpar\tqr\tldot\tx8812 \b\caps\f4\fs20 {\cf1 8 Containers}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285543 {\field{\*\fldinst PAGEREF _Toc330285543 }{\fldrslt 22}}}} \par \pard\plain \s47\nowidctlpar\tqr\tldot\tx8812 \scaps\f4\fs20 {\b\cf1 8.1 Sequences}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285544 {\field{\*\fldinst PAGEREF _Toc330285544 }{\fldrslt 24}}}} \par \pard\plain \s48\li240\nowidctlpar\tqr\tldot\tx8812 \i\f4\fs20 {\cf1 8.1.1 Vector}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285545 {\field{\*\fldinst PAGEREF _Toc330285545 }{\fldrslt 26}}}} \par \pard \s48\li240\nowidctlpar\tqr\tldot\tx8812 {\cf1 8.1.3 Deque}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285546 {\field{\*\fldinst PAGEREF _Toc330285546 }{\fldrslt 33}}}} \par \pard\plain \s47\nowidctlpar\tqr\tldot\tx8812 \scaps\f4\fs20 {\b\cf1 8.2 Associative containers}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285547 {\field{\*\fldinst PAGEREF _Toc330285547 }{\fldrslt 35}}}} \par \pard\plain \s48\li240\nowidctlpar\tqr\tldot\tx8812 \i\f4\fs20 {\cf1 8.2.1 Set}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285548 {\field{\*\fldinst PAGEREF _Toc330285548 }{\fldrslt 38}}}} \par \pard \s48\li240\nowidctlpar\tqr\tldot\tx8812 {\cf1 8.2.2 Multiset}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285549 {\field{\*\fldinst PAGEREF _Toc330285549 }{\fldrslt 40}}}} \par {\cf1 8.2.3 Map}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285550 {\field{\*\fldinst PAGEREF _Toc330285550 }{\fldrslt 41}}}} \par {\cf1 8.2.4 Multimap}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285551 {\field{\*\fldinst PAGEREF _Toc330285551 }{\fldrslt 44}}}} \par \pard\plain \s46\sb120\sa120\nowidctlpar\tqr\tldot\tx8812 \b\caps\f4\fs20 {\cf1 9 Stream iterators}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285552 {\field{\*\fldinst PAGEREF _Toc330285552 }{\fldrslt 46}}}} \par \pard\plain \s47\nowidctlpar\tqr\tldot\tx8812 \scaps\f4\fs20 {\b\cf1 9.1 Istream Iterator}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285553 {\field{\*\fldinst PAGEREF _Toc330285553 }{\fldrslt 46}}}} \par \pard \s47\nowidctlpar\tqr\tldot\tx8812 {\b\cf1 9.2 Ostream iterator}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285554 {\field{\*\fldinst PAGEREF _Toc330285554 }{\fldrslt 47}}}} \par \pard\plain \s46\sb120\sa120\nowidctlpar\tqr\tldot\tx8812 \b\caps\f4\fs20 {\cf1 10 Algorithms}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285555 {\field{\*\fldinst PAGEREF _Toc330285555 }{\fldrslt 48}}}} \par \pard\plain \s47\nowidctlpar\tqr\tldot\tx8812 \scaps\f4\fs20 {\b\cf1 10.1 Non-mutating sequence operations}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285556 {\field{\*\fldinst PAGEREF _Toc330285556 }{\fldrslt 48}}}} \par \pard\plain \s48\li240\nowidctlpar\tqr\tldot\tx8812 \i\f4\fs20 {\cf1 10.1.1 For each}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285557 {\field{\*\fldinst PAGEREF _Toc330285557 }{\fldrslt 48}}}} \par \pard \s48\li240\nowidctlpar\tqr\tldot\tx8812 {\cf1 10.1.2 Find}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285558 {\field{\*\fldinst PAGEREF _Toc330285558 }{\fldrslt 49}}}} \par {\cf1 10.1.3 Adjacent find}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285559 {\field{\*\fldinst PAGEREF _Toc330285559 }{\fldrslt 49}}}} \par {\cf1 10.1.4 Count}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285560 {\field{\*\fldinst PAGEREF _Toc330285560 }{\fldrslt 49}}}} \par {\cf1 10.1.5 Mismatch}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285561 {\field{\*\fldinst PAGEREF _Toc330285561 }{\fldrslt 50}}}} \par {\cf1 10.1.6 Equal}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285562 {\field{\*\fldinst PAGEREF _Toc330285562 }{\fldrslt 50}}}} \par {\cf1 10.1.7 Search}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285563 {\field{\*\fldinst PAGEREF _Toc330285563 }{\fldrslt 50}}}} \par \pard\plain \s47\nowidctlpar\tqr\tldot\tx8812 \scaps\f4\fs20 {\b\cf1 10.2 Mutating sequence operations}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285564 {\field{\*\fldinst PAGEREF _Toc330285564 }{\fldrslt 51}}}} \par \pard\plain \s48\li240\nowidctlpar\tqr\tldot\tx8812 \i\f4\fs20 {\cf1 10.2.1 Copy}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285565 {\field{\*\fldinst PAGEREF _Toc330285565 }{\fldrslt 51}}}} \par \pard \s48\li240\nowidctlpar\tqr\tldot\tx8812 {\cf1 10.2.2 Swap}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285566 {\field{\*\fldinst PAGEREF _Toc330285566 }{\fldrslt 51}}}} \par {\cf1 10.2.3 Transform}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285567 {\field{\*\fldinst PAGEREF _Toc330285567 }{\fldrslt 52}}}} \par {\cf1 10.2.4 Replace}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285568 {\field{\*\fldinst PAGEREF _Toc330285568 }{\fldrslt 52}}}} \par {\cf1 10.2.5 Fill}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285569 {\field{\*\fldinst PAGEREF _Toc330285569 }{\fldrslt 53}}}} \par {\cf1 10.2.6 Generate}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285570 {\field{\*\fldinst PAGEREF _Toc330285570 }{\fldrslt 53}}}} \par {\cf1 10.2.7 Remove}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285571 {\field{\*\fldinst PAGEREF _Toc330285571 }{\fldrslt 53}}}} \par {\cf1 10.2.8 Unique}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285572 {\field{\*\fldinst PAGEREF _Toc330285572 }{\fldrslt 54}}}} \par {\cf1 10.2.9 Reverse}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285573 {\field{\*\fldinst PAGEREF _Toc330285573 }{\fldrslt 54}}}} \par {\cf1 10.2.10 Rotate}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285574 {\field{\*\fldinst PAGEREF _Toc330285574 }{\fldrslt 55}}}} \par {\cf1 10.2.11 Random shuffle}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285575 {\field{\*\fldinst PAGEREF _Toc330285575 }{\fldrslt 55}}}} \par {\cf1 10.2.12 Partitions}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285576 {\field{\*\fldinst PAGEREF _Toc330285576 }{\fldrslt 56}}}} \par \pard\plain \s47\nowidctlpar\tqr\tldot\tx8812 \scaps\f4\fs20 {\b\cf1 10.3 Sorting and related operations}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285577 {\field{\*\fldinst PAGEREF _Toc330285577 }{\fldrslt 56}}}} \par \pard\plain \s48\li240\nowidctlpar\tqr\tldot\tx8812 \i\f4\fs20 {\cf1 10.3.1 Sort}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285578 {\field{\*\fldinst PAGEREF _Toc330285578 }{\fldrslt 56}}}} \par \pard \s48\li240\nowidctlpar\tqr\tldot\tx8812 {\cf1 10.3.2 Nth element}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285579 {\field{\*\fldinst PAGEREF _Toc330285579 }{\fldrslt 58}}}} \par {\cf1 10.3.3 Binary search}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285580 {\field{\*\fldinst PAGEREF _Toc330285580 }{\fldrslt 58}}}} \par {\cf1 10.3.4 Merge}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285581 {\field{\*\fldinst PAGEREF _Toc330285581 }{\fldrslt 59}}}} \par {\cf1 10.3.5 Set operations on sorted structures}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285582 {\field{\*\fldinst PAGEREF _Toc330285582 }{\fldrslt 60}}}} \par {\cf1 10.3.6 Heap operations}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285583 {\field{\*\fldinst PAGEREF _Toc330285583 }{\fldrslt 62}}}} \par {\cf1 10.3.7 Minimum and maximum}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285584 {\field{\*\fldinst PAGEREF _Toc330285584 }{\fldrslt 63}}}} \par {\cf1 10.3.8 Lexicographical comparison}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285585 {\field{\*\fldinst PAGEREF _Toc330285585 }{\fldrslt 64}}}} \par {\cf1 10.3.9 Permutation generators}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285586 {\field{\*\fldinst PAGEREF _Toc330285586 }{\fldrslt 64}}}} \par \pard\plain \s47\nowidctlpar\tqr\tldot\tx8812 \scaps\f4\fs20 {\b\cf1 10.4 Generalized numeric operations}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285587 {\field{\*\fldinst PAGEREF _Toc330285587 }{\fldrslt 65}}}} \par \pard\plain \s48\li240\nowidctlpar\tqr\tldot\tx8812 \i\f4\fs20 {\cf1 10.4.1 Accumulate}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285588 {\field{\*\fldinst PAGEREF _Toc330285588 }{\fldrslt 65}}}} \par \pard \s48\li240\nowidctlpar\tqr\tldot\tx8812 {\cf1 10.4.2 Inner product}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285589 {\field{\*\fldinst PAGEREF _Toc330285589 }{\fldrslt 65}}}} \par {\cf1 10.4.3 Partial sum}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285590 {\field{\*\fldinst PAGEREF _Toc330285590 }{\fldrslt 65}}}} \par {\cf1 10.4.4 Adjacent difference}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285591 {\field{\*\fldinst PAGEREF _Toc330285591 }{\fldrslt 66}}}} \par \pard\plain \s46\sb120\sa120\nowidctlpar\tqr\tldot\tx8812 \b\caps\f4\fs20 {\cf1 11 Adaptors}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285592 {\field{\*\fldinst PAGEREF _Toc330285592 }{\fldrslt 66}}}} \par \pard\plain \s47\nowidctlpar\tqr\tldot\tx8812 \scaps\f4\fs20 {\b\cf1 11.1 Container adaptors}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285593 {\field{\*\fldinst PAGEREF _Toc330285593 }{\fldrslt 66}}}} \par \pard\plain \s48\li240\nowidctlpar\tqr\tldot\tx8812 \i\f4\fs20 {\cf1 11.1.1 Stack}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285594 {\field{\*\fldinst PAGEREF _Toc330285594 }{\fldrslt 66}}}} \par \pard \s48\li240\nowidctlpar\tqr\tldot\tx8812 {\cf1 11.1.2 Queue}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285595 {\field{\*\fldinst PAGEREF _Toc330285595 }{\fldrslt 67}}}} \par {\cf1 11.1.3 Priority queue}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285596 {\field{\*\fldinst PAGEREF _Toc330285596 }{\fldrslt 68}}}} \par \pard\plain \s47\nowidctlpar\tqr\tldot\tx8812 \scaps\f4\fs20 {\b\cf1 11.2 Iterator adaptors}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285597 {\field{\*\fldinst PAGEREF _Toc330285597 }{\fldrslt 69}}}} \par \pard\plain \s48\li240\nowidctlpar\tqr\tldot\tx8812 \i\f4\fs20 {\cf1 11.2.1 Reverse iterators}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285598 {\field{\*\fldinst PAGEREF _Toc330285598 }{\fldrslt 69}}}} \par \pard \s48\li240\nowidctlpar\tqr\tldot\tx8812 {\cf1 11.2.2 Insert iterators}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285599 {\field{\*\fldinst PAGEREF _Toc330285599 }{\fldrslt 72}}}} \par {\cf1 11.2.3 Raw storage iterator}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285600 {\field{\*\fldinst PAGEREF _Toc330285600 }{\fldrslt 74}}}} \par \pard\plain \s47\nowidctlpar\tqr\tldot\tx8812 \scaps\f4\fs20 {\b\cf1 11.3 Function adaptors}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285601 {\field{\*\fldinst PAGEREF _Toc330285601 }{\fldrslt 75}}}} \par \pard\plain \s48\li240\nowidctlpar\tqr\tldot\tx8812 \i\f4\fs20 {\cf1 11.3.1 Negators}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285602 {\field{\*\fldinst PAGEREF _Toc330285602 }{\fldrslt 75}}}} \par \pard \s48\li240\nowidctlpar\tqr\tldot\tx8812 {\cf1 11.3.2 Binders}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285603 {\field{\*\fldinst PAGEREF _Toc330285603 }{\fldrslt 75}}}} \par {\cf1 11.3.3 Adaptors for pointers to functions}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285604 {\field{\*\fldinst PAGEREF _Toc330285604 }{\fldrslt 76}}}} \par \pard\plain \s46\sb120\sa120\nowidctlpar\tqr\tldot\tx8812 \b\caps\f4\fs20 {\cf1 12 Memory Handling}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285605 {\field{\*\fldinst PAGEREF _Toc330285605 }{\fldrslt 77}}}} \par \pard\plain \s47\nowidctlpar\tqr\tldot\tx8812 \scaps\f4\fs20 {\b\cf1 12.1 Primitives}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285606 {\field{\*\fldinst PAGEREF _Toc330285606 }{\fldrslt 77}}}} \par \pard \s47\nowidctlpar\tqr\tldot\tx8812 {\b\cf1 12.2 Specialized algorithms}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285607 {\field{\*\fldinst PAGEREF _Toc330285607 }{\fldrslt 78}}}} \par \pard\plain \s46\sb120\sa120\nowidctlpar\tqr\tldot\tx8812 \b\caps\f4\fs20 {\cf1 13 Acknowledgments}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285608 {\field{\*\fldinst PAGEREF _Toc330285608 }{\fldrslt 79}}}} \par \pard \s46\sb120\sa120\nowidctlpar\tqr\tldot\tx8812 {\cf1 14 Bibliography}\tab {\field{\*\fldinst GOTOBUTTON _Toc330285609 {\field{\*\fldinst PAGEREF _Toc330285609 }{\fldrslt 80}}}} \par \pard\plain \s35\fi-532\li532\ri-548\sb120\sl280\slmult0\nowidctlpar \f8 }}\pard\plain \s35\fi-532\li532\ri-548\sb120\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 \par \page \par }\pard\plain \s34\ri-548\sb320\sl280\slmult0\nowidctlpar \f8 {\b\f9\cf1 {\*\bkmkstart _Toc330285519}1 Introduction}{\f9\cf1 {\*\bkmkend _Toc330285519} \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 The Standard Template Library provides a set of well structured generic C++ components that work together in a seamless way. Special care has been taken to ensure th at all the template algorithms work not only on the data structures in the library, but also on built-in C++ data structures. For example, all the algorithms work on regular pointers. The orthogonal design of the library allows programmers to use library data structures with their own algorithms, and to use library algorithms with their own data structures. The well specified semantic and complexity requirements guarantee that a user component will work with the library, and that it will work efficiently. This flexibility ensures the widespread utility of the library. \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 Another important consideration is efficiency. C++ is successful because it combines expressive power with efficiency. Much effort has been spent to verify that every template component in the library has a generic implementation that performs within a fe w percentage points of the efficiency of the corresponding hand coded routine. \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 The third consideration in the design has been to develop a library structure that, while being natural and easy to grasp, is based on a firm theoretical foundation. \par }\pard\plain \s34\ri-548\sb320\sl280\slmult0\nowidctlpar \f8 {\b\f9\cf1 {\*\bkmkstart _Toc330285520}2 Structure of the library}{\f9\cf1 {\*\bkmkend _Toc330285520} \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 The library contains five main kinds of components: \par }\pard\plain \s19\fi-230\li590\ri-548\sb40\sl260\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 \endash \tab algorithm: defines a computational procedure. \par }\pard \s19\fi-230\li590\ri-548\sb40\sl260\slmult0\nowidctlpar {\f18\fs20\cf1 \endash \tab container: manages a set of memory locations. \par \endash \tab iterator: provides a means for an algorithm to traverse through a container. \par \endash \tab function object: encapsulates a function in an object for use by other components. \par \endash \tab adaptor: adapts a component to provide a different interface. \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 Such decomposition allows us to dramatically reduce the component space. For example, instead of providing a search member function for every kind of container we provide a single version that works with all of them as long as a basic set of requirements is satisfied. \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 The following description helps clarify the structure of the library. If software components are tabulated as a three-dimensional array, where one dimension represents different data types (e.g. int, double), the second dimension represents different cont ainers (e.g. vector, linked-list, file), a nd the third dimension represents different algorithms on the containers (e.g. searching, sorting, rotation), if i, j, and k are the size of the dimensions, then i*j*k different versions of code have to be designed. By using template functions that are pa rameterized by a data type, we need only j*k versions. Further, by making our algorithms work on different containers, we need merely j+k versions. This significantly simplifies software design work and also makes it possible to use components in the libr ary together with user defined components in a very flexible way. A user may easily define a specialized container class and use the library\rquote s sort function to sort it. A user may provide a different comparison function for the sort either as a regular poin ter to a comparison function, or as a function object (an object with an operator() defined) that does the comparisons. If a user needs to iterate through a container in the reverse direction, the reverse_iterator adaptor allows that. \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 The library extends th e basic C++ paradigms in a consistent way, so it is easy for a C/C++ programmer to start using the library. For example, the library contains a merge template function. When a user has two arrays a and b to be merged into c it can be done with: \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 \par }\pard\plain \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar \f8 {\f3\fs18\cf1 int a[1000]; \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 int b[2000]; \par int c[3000]; \par ... \par merge(a, a + 1000, b, b + 2000, c); \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 When a user wants to merge a vector and a list (both of which are template classes in the library) and put the result into a freshly allocated uninitialized storage it can be done with: \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 \par }\pard\plain \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar \f8 {\f3\fs18\cf1 vector a; \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 list b; \par ... \par Employee* c = allocate(a.size() + b.size(), (Employee*)0); \par merge(a.begin(), a.end(), b.begin(), b.end(), \par \tab raw_storage_iterator(c)); \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 where begin() and end() are member functions of containers that return the right types of iterators or pointer-like objects that allow the merge to do the job and }{ \f3\fs18\cf1 raw_storage_iterator is an adapter that allows algorithms to put results directly into uninitialized memory by calling the appropriate copy constructor. \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 In many cases it is useful to iterate through input/output streams in the same way as through regular data structures. For example, if we want to merge two data structures and then store them in a file, it would be nice to avoid creation of an auxiliary d ata structure for the result, instead storing the result directly into the corresponding file. The library provides both istream_iterator and ostream_iterator template classes to make many of the library algorithms work with I/O streams that represent hom ogenous aggregates of data. Here is a program that reads a file of integers from the standard input, removes all those that are divisible by its command argument, and writes the result to the standard output: \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 \par }\pard\plain \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar \f8 {\f3\fs18\cf1 main(int argc, char** argv) \{ \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 \tab if (argc != 2) throw(\rdblquote usage: remove_if_divides integer\\n\rdblquote ); \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 \tab remove_copy_if(istream_iterator(cin), istream_iterator(), \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 \tab \tab ostream_iterator(cout, \rdblquote \\n\rdblquote ), \par \tab \tab not1(bind2nd(modulus(), atoi(argv[1])))); \par \} \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 All the work is done by remove_copy_if which reads inte gers one by one until the input iterator becomes equal to the end-of-stream iterator that is constructed by the constructor with no arguments. (In general, all the algorithms work in a \ldblquote from here to there\rdblquote fashion taking two iterators that signify the beg inning and the end of the input.) Then remove_copy_if writes the integers that pass the test onto the output stream through the output iterator that is bound to cout. As a predicate, remove_copy_if uses a function object constructed from a function object , modulus, which takes i and j and returns i%j, as a binary predicate and makes it into a unary predicate by using bind2nd to bind the second argument to the command line argument, atoi(argv[1]). Then the negation of this unary predicate is obtained us ing function adaptor not1. \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 A somewhat more realistic example is a filter program that takes a file and randomly shuffles its lines. \par }\pard\plain \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar \f8 {\f3\fs18\cf1 main(int argc, char**) \{ \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 \tab if (argc != 1) throw(\rdblquote usage: shuffle\\n\rdblquote ); \par \tab vector v; \par \tab copy(istream_iterator(cin), istream_iterator(), \par \tab \tab inserter(v, v.end())); \par \tab random_shuffle(v.begin(), v.end()); \par \tab copy(v.begin(), v.end(), ostream_iterator(cout)); \par \} \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 In this example, copy moves lines from the standard input into a vector, but since the vector is not pre-allocated it uses an insert iterator to insert the lines one by one into the vector. (This technique allows all of the copying functions to work in th e usual overwrite mode as well as in the insert mode.) Then random_shuffle shuffles the vector and another call to copy copies it onto the cout stream. \par }\pard\plain \s34\ri-548\sb320\sl280\slmult0\nowidctlpar \f8 {\b\f9\cf1 {\*\bkmkstart _Toc330285521}3 Requirements}{\f9\cf1 {\*\bkmkend _Toc330285521} \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 To ensure that the different components in a library work together, they must satisfy some basic requirements. Requirements should be as general as possible, so instead of saying \ldblquote class X has to define a member function operator++(),\rdblquote we say \ldblquote for any object x of class X, ++x is defined.\rdblquote (It is unspecified whether the operator is a member or a global function.) Requirements are stated in terms of well-defined expressions, which define valid terms of the types that satisfy the requirements. For every set of requirements there is a table that specifies an initial set of the valid expressions and their semantics. Any generic algorithm that u ses the requirements has to be written in terms of the valid expressions for its formal type parameters. \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 If an operation is required to be linear time, it means no worse than linear time, and a constant time operation satisfies the requirement. \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 In some case s we present the semantic requirements using C++ code. Such code is intended as a specification of equivalence of a construct to another construct, not necessarily as the way the construct must be implemented (although in some cases the code given is unam biguously the optimum implementation). \par }\pard\plain \s34\ri-548\sb320\sl280\slmult0\nowidctlpar \f8 {\b\f9\cf1 {\*\bkmkstart _Toc330285522}4 Core components}{\f9\cf1 {\*\bkmkend _Toc330285522} \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 This section contains some basic template functions and classes that are used throughout the rest of the library. \par }\pard\plain \s37\ri-548\sb200\sl260\slmult0\nowidctlpar \f8 {\b\f9\fs22\cf1 {\*\bkmkstart _Toc330285523}4.1 Operators}{\f9\fs22\cf1 {\*\bkmkend _Toc330285523} \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 To avoid redundant definitions of operator!= out of operator== and operators>, <=, and >= out of operator< the library provides the following: \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 \par }\pard\plain \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar \f8 {\f3\fs18\cf1 template \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 inline bool operator!=(const T& x, const T& y) \{ \par \tab return !(x == y); \par \} \par \par template \par inline bool operator>(const T& x, const T& y) \{ \par \tab return y < x; \par \} \par \par template \par inline bool operator<=(const T& x, const T& y) \{ \par \tab return !(y < x); \par \} \par \par template \par inline bool operator>=(const T& x, const T& y) \{ \par \tab return !(x < y); \par \} \par }\pard\plain \s37\ri-548\sb200\sl260\slmult0\nowidctlpar \f8 {\b\f9\fs22\cf1 {\*\bkmkstart _Toc330285524}4.2 Pair}{\f9\fs22\cf1 {\*\bkmkend _Toc330285524} \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 The library includes templates for heterogeneous pairs of values. \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 \par }\pard\plain \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar \f8 {\f3\fs18\cf1 template \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 struct pair \{ \par \tab T1 first; \par \tab T2 second; \par \tab pair(const T1& x, const T2& y) : first(x), second(y) \{\} \par \}; \par \tab \par template \par inline bool operator==(const pair& x, const pair& y) \{ \par \tab return x.first == y.first && x.second == y.second; \par \} \par \par template \par inline bool operator<(const pair& x, const pair& y) \{ \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 \tab return x.first < y.first || (!(y.first < x.first) && x.second < y.second); \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 \} \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 The library provides a matching template function make_pair to simplify their construction. Instead of saying, for example, \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 \par }\pard\plain \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar \f8 {\f3\fs18\cf1 return pair(5, 3.1415926); // explicit types \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 one may say \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 \par }\pard\plain \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar \f8 {\f3\fs18\cf1 return make_pair(5, 3.1415926); // types are deduced \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 \par template \par inline pair make_pair(const T1& x, const T2& y) \{ \par \tab return pair(x, y); \par }\pard\plain \s34\ri-548\sb320\sl280\slmult0\nowidctlpar \f8 {\b\f9\cf1 {\*\bkmkstart _Toc330285525}5 Iterators}{\f9\cf1 {\*\bkmkend _Toc330285525} \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 Iterators are a generalization of pointers that allow a programmer to work with different data structures (containers) in a uniform manner. To be able to construct template algorithms that wor k correctly and efficiently on different types of data structures, we need to formalize not just the interfaces but also the semantics and complexity assumptions of iterators. Iterators are objects that have operator* returning a value of some class or bu ilt-in type T called a value type of the iterator. For every iterator type X for which equality is defined, there is a corresponding signed integral type called the distance type of the iterator. \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 Since iterators are a generalization of pointers, their sema ntics is a generalization of the semantics of pointers in C++. This assures that every template function that takes iterators works with regular pointers. Depending on the operations defined on them, there are five categories of iterators: input iterators , output iterators, forward iterators, bidirectional iterators and random access iterators. Forward iterators satisfy all the requirements of the input and output iterators and can be used whenever either kind is specified. Bidirectional iterators satisfy a ll the requirements of the forward iterators and can be used whenever a forward iterator is specified. Random access iterators satisfy all the requirements of bidirectional iterators and can be used whenever a bidirectional iterator is specified. There is an additional attribute that forward, bidirectional and random access iterators might have, that is, they can be mutable or constant depending on whether the result of the operator* behaves as a reference or as a reference to a constant. Constant iterato rs do not satisfy the requirements for output iterators. \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 Just as a regular pointer to an array guarantees that there is a pointer value pointing past the last element of the array, so for any iterator type there is an iterator value that points past the last element of a corresponding container. These values ar e called past-the-end values. Values of the iterator for which the operator* is defined are called dereferenceable. The library never assumes that past-the-end values are dereferenceable. Iterators mig ht also have singular values that are not associated with any container. For example, after the declaration of an uninitialized pointer x (as with int* x;), x should always be assumed to have a singular value of a pointer. Results of most expressions are undefined for singular values. The only exception is an assignment of a non-singular value to an iterator that holds a singular value. In this case the singular value is overwritten the same way as any other value. Dereferenceable and past-the-end values are always non-singular. \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 An iterator j is called reachable from an iterator i if and only if there is a finite sequence of applications of operator++ to i that makes i == j. If i and j refer to the same container, then either j is reachable from i, or i is reachable from j, or bo th (i == j). \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 Most of the library\rquote s algorithmic templates that operate on data structures have interfaces that use ranges. A range is a pair of iterators that designate the beginning and end of the computation. A range [i, i) is an em pty range; in general, a range [i, j) refers to the elements in the data structure starting with the one pointed to by i and up to but not including the one pointed to by j. Range [i, j) is valid if and only if j is reachable from i. The result of the app lication of the algorithms in the library to invalid ranges is undefined. \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 All the categories of iterators require only those functions that are realizable for a given category in constant time (amortized). Therefore, requirement tables for the iterators do not have a complexity column. \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 In the following sections, we assume: a and b are values of X, n is a value of the distance type Distance, u, tmp, and m are identifiers, r and s are lvalues of X, t is a value of value type T. \par }\pard\plain \s37\ri-548\sb200\sl260\slmult0\nowidctlpar \f8 {\b\f9\fs22\cf1 {\*\bkmkstart _Toc330285526}5.1 Input iterators}{\f9\fs22\cf1 {\*\bkmkend _Toc330285526} \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 A class or a built-in type X satisfies the requirements of an input iterator for the value type T if the following expressions are valid: \par }\pard \s17\qc\ri-548\sb140\sl280\slmult0\nowidctlpar {\b\cf1 Table 2: Input iterator requirements \par }\pard \s17\qc\ri-548\sb140\sl280\slmult0\nowidctlpar {\cf1 \par }\trowd \trqc \clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrdb\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx2808\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrdb\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx4680\clbrdrt\brdrs\brdrw15 \clbrdrl \brdrs\brdrw15 \clbrdrb\brdrdb\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx6696\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrdb\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx10440 \pard \s17\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 expression\cell }\pard \s17\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 return type\cell }\pard \s17\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 operational semantics\cell }\pard \s17\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 assertion/note \par }\pard\plain \s21\qj\sl280\slmult0\nowidctlpar\intbl \f8 {\fs20\cf1 pre/post-condition\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\trowd \trqc \clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx2808\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx4680\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx6696\clbrdrt\brdrs\brdrw15 \clbrdrl \brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx10440 \pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 X(a)\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard \s21\qc\sl280\slmult0 \nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 a == X(a). \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 note: a destructor is assumed.\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 X u(a); \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 X u = a;\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard \s21\qc\sl280\slmult0 \nowidctlpar\intbl {\fs20\cf1 post: u == a.\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 a == b\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 convertible to bool\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 == is an equivalence relation.\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 a != b\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 convertible to bool\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 !(a == b)\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard\plain \widctlpar\intbl \f8 {\f3\fs18\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 *a\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 convertible to T \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 pre: a is dereferenceable. \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 a == b implies *a == *b.\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 ++r\cell }\pard \s21\qc\sl280\slmult0 \nowidctlpar\intbl {\f3\fs18\cf1 X&\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 pre: r is dereferenceable. \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 post: r is dereferenceable or r is past-the-end. \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 &r == &++r.\cell }\pard\plain \widctlpar\intbl \f8 {\f3\fs18\cf1 \row }\trowd \trqc \clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx2808\clbrdrt \brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx4680\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx6696\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb \brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx10440 \pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 r++\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 X\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl { \f3\fs18\cf1 \{ X tmp = r; \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 ++r; \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 return tmp; \}\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard\plain \widctlpar\intbl \f8 {\f3\fs18\cf1 \row }\pard \qc\ri-548\sl280\slmult0\nowidctlpar { \f3\fs18\cf1 \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f3\fs18\cf1 NOTE: For input iterators, r == s does not imply ++r == ++s. (Equality does not guarantee the substitution property or referenti al transparency.) Algorithms on input iterators should never attempt to pass through the same iterator twice. They should be single pass algorithms. Value type }{\i\f3\fs18\cf1 T}{\i\f18\fs20\cf1 is not required to be an lvalue type. These algorithms can be used with istreams as the source of the input data through the istream_iterator class.}{\f18\fs20\cf1 \par }\pard\plain \s37\ri-548\sb200\sl260\slmult0\nowidctlpar \f8 {\b\f9\fs22\cf1 {\*\bkmkstart _Toc330285527}5.2 Output iterators}{\f9\fs22\cf1 {\*\bkmkend _Toc330285527} \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 A class or a built-in type X satisfies the requirements of an output iterator if the following expressions are valid: \par }\pard \s17\qc\ri-548\sb140\sl280\slmult0\nowidctlpar {\b\cf1 Table 3: Output iterator requirements \par }\pard \s17\qc\ri-548\sb140\sl280\slmult0\nowidctlpar {\cf1 \par }\trowd \trqc \clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrdb\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx2808\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrdb\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx4536\clbrdrt\brdrs\brdrw15 \clbrdrl \brdrs\brdrw15 \clbrdrb\brdrdb\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx6552\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrdb\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx10152 \pard \s17\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 expression\cell }\pard \s17\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 return type\cell }\pard \s17\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 operational semantics\cell }\pard \s17\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 assertion/note \par }\pard\plain \s21\qj\sl280\slmult0\nowidctlpar\intbl \f8 {\fs20\cf1 pre/post-condition\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\trowd \trqc \clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx2808\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx4536\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx6552\clbrdrt\brdrs\brdrw15 \clbrdrl \brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx10152 \pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 X(a)\cell \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard \s21\qc\sl280\slmult0 \nowidctlpar\intbl {\fs20\cf1 *a = t is equivalent to *X(a) = t. \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 note: a destructor is assumed.\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 X u(a); \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 X u = a;\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard \s21\qc\sl280\slmult0 \nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard\plain \widctlpar\intbl \f8 {\f3\fs18\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 *a = t\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 result is not used \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 \cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 ++r\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 X&\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard\plain \widctlpar\intbl \f8 { \f3\fs18\cf1 \row }\trowd \trqc \clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx2808\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx4536\clbrdrt \brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx6552\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx10152 \pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 { \f3\fs18\cf1 r++\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 X or X&\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 \cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard \qc\ri-548\sl280\slmult0\nowidctlpar {\fs20\cf1 \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\fs20\cf1 NOTE: The only valid use of an operator* is on the left side of the assignment statement. Assignment through the same value of the iterator happens only once. Algorithms on output iterators should never attempt to pass through the same iterator twice. The y should be single pass algorithms. Equality and i nequality are not necessarily defined. Algorithms that take output iterators can be used with ostreams as the destination for placing data through the ostream_iterator class as well as with insert iterators and insert pointers. In particular, the followin g two conditions should hold: first, any iterator value should be assigned through before it is incremented (this is, for an output iterator i, i++; i++; is not a valid code sequence); second, any value of an output iterator may have at most one active co py at any given time (for example, i = j; *++i = a; *j = b; is not a valid code sequence). \par }\pard\plain \s37\ri-548\sb200\sl260\slmult0\nowidctlpar \f8 {\b\f9\fs22\cf1 {\*\bkmkstart _Toc330285528}5.3 Forward iterators}{\f9\fs22\cf1 {\*\bkmkend _Toc330285528} \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 A class or a built-in type X satisfies the requirements of a forward iterator if the following expressions are \line valid: \par }\pard \s17\qc\ri-548\sb140\sl280\slmult0\nowidctlpar {\b\cf1 Table 4: Forward iterator requirements \par }\pard \s17\qc\ri-548\sb140\sl280\slmult0\nowidctlpar {\cf1 \par }\trowd \trqc \clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrdb\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx2808\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrdb\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx4680\clbrdrt\brdrs\brdrw15 \clbrdrl \brdrs\brdrw15 \clbrdrb\brdrdb\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx6696\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrdb\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx10440 \pard \s17\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 expression\cell }\pard \s17\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 return type\cell }\pard \s17\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 operational semantics\cell }\pard \s17\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 assertion/note \par }\pard\plain \s21\qj\sl280\slmult0\nowidctlpar\intbl \f8 {\fs20\cf1 pre/post-condition\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\trowd \trqc \clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx2808\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx4680\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx6696\clbrdrt\brdrs\brdrw15 \clbrdrl \brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx10440 \pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 X u;\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard \s21\qc\sl280\slmult0 \nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 note: u might have a singular value. \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 note: a destructor is assumed.\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 X()\cell }\pard \s21\qc\sl280\slmult0 \nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 note: X() might be singular.\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 X(a)\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard \s21\qc\sl280\slmult0 \nowidctlpar\intbl {\f3\fs18\cf1 a == X(a).\cell }\pard\plain \widctlpar\intbl \f8 {\f3\fs18\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 X u(a); \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 X u = a;\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 X u; u = a;\cell }\pard \s21\qc\sl280\slmult0 \nowidctlpar\intbl {\fs20\cf1 post: u == a.\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 a == b\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 convertible to bool\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 == is an equivalence relation.\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 a != b\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 convertible to bool\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 !(a == b)\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard\plain \widctlpar\intbl \f8 {\f3\fs18\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 r = a\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 X& \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 post: r == a.\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 { \f3\fs18\cf1 *a\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 convertible to T \par \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 pre: a is dereferenceable. \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 a == b implies *a == *b. \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 If X is mutable, *a = t is valid.\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 ++r\cell }\pard \s21\qc\sl280\slmult0 \nowidctlpar\intbl {\f3\fs18\cf1 X&\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 pre: r is dereferenceable. \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 post: r is dereferenceable or r is past-the-end. \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 r == s and r is dereferenceable implies ++r == ++s. \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 &r == &++r.\cell }\pard\plain \widctlpar\intbl \f8 {\f3\fs18\cf1 \row }\trowd \trqc \clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx2808\clbrdrt \brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx4680\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx6696\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb \brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx10440 \pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 r++\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 X\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl { \f3\fs18\cf1 \{ X tmp = r; \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 ++r; \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 return tmp; \}\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard\plain \widctlpar\intbl \f8 {\f3\fs18\cf1 \row }\pard \qc\ri-548\sl280\slmult0\nowidctlpar { \f3\fs18\cf1 \par }\pard \qc\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f3\fs18\cf1 NOTE: The fact that r == s implies ++r == ++s (which is not true for inpu t and output iterators) and the removal on the restrictions on the number of the assignments through the iterator (which applies to output iterators) allows the use of multi-pass one-directional algorithms with forward iterators. \par }\pard\plain \s37\ri-548\sb200\sl260\slmult0\nowidctlpar \f8 {\b\f9\fs22\cf1 {\*\bkmkstart _Toc330285529}5.4 Bidirectional iterators}{\f9\fs22\cf1 {\*\bkmkend _Toc330285529} \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 A class or a built-in type X satisfies the requirements of a bidirectional iterator if to the table that specifies forward iterators we add the following lines: \par }\pard \s17\qc\ri-548\sb140\sl280\slmult0\nowidctlpar {\b\cf1 Table 5: Bidirectional iterator requirements (in addition to forward iterator) \par }\pard \s17\qc\ri-548\sb140\sl280\slmult0\nowidctlpar {\cf1 \par }\trowd \trqc \clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrdb\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx2808\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrdb\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx4680\clbrdrt\brdrs\brdrw15 \clbrdrl \brdrs\brdrw15 \clbrdrb\brdrdb\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx6696\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrdb\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx10440 \pard \s17\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 expression\cell }\pard \s17\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 return type\cell }\pard \s17\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 operational semantics\cell }\pard \s17\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 assertion/note \par }\pard\plain \s21\qj\sl280\slmult0\nowidctlpar\intbl \f8 {\fs20\cf1 pre/post-condition\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\trowd \trqc \clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx2808\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx4680\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx6696\clbrdrt\brdrs\brdrw15 \clbrdrl \brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx10440 \pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 --r\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 X&\cell }\pard \s21\qc\sl280\slmult0 \nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 pre: there exists s such that r == ++s. \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 post: s is dereferenceable. \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 --(++r) == r. \par --r == --s implies r == s. \par &r == &--r.\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\trowd \trqc \clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx2808\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx4680\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx6696\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx10440 \pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 r--\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 X\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \{ X tmp = r; \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 --r; \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 return tmp; \}\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard\plain \widctlpar\intbl \f8 {\f3\fs18\cf1 \row }\pard \qc\ri-548\sl280\slmult0\nowidctlpar { \f3\fs18\cf1 \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f3\fs18\cf1 NOTE: Bidirectional iterators allow algorithms to move iterators backward as well as forward. \par }\pard\plain \s37\ri-548\sb200\sl260\slmult0\nowidctlpar \f8 {\b\f9\fs22\cf1 {\*\bkmkstart _Toc330285530}5.5 Random access iterators}{\f9\fs22\cf1 {\*\bkmkend _Toc330285530} \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 A class or a built-in type X satisfies the requirements of a random access iterator if to the table that specifies bidirectional iterators we add the following lines: \par }\pard \s17\qc\ri-548\sb140\sl280\slmult0\nowidctlpar {\b\cf1 Table 6: Random access iterator requirements (in addition to bidirectional iterator) \par }\pard \s17\qc\ri-548\sb140\sl280\slmult0\nowidctlpar {\cf1 \par }\trowd \trqc \clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrdb\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx2808\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrdb\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx4680\clbrdrt\brdrs\brdrw15 \clbrdrl \brdrs\brdrw15 \clbrdrb\brdrdb\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx7128\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrdb\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx10872 \pard \s17\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 expression\cell }\pard \s17\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 return type\cell }\pard \s17\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 operational semantics\cell }\pard \s17\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 assertion/note \par }\pard\plain \s21\qj\sl280\slmult0\nowidctlpar\intbl \f8 {\fs20\cf1 pre/post-condition\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\trowd \trqc \clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx2808\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx4680\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx7128\clbrdrt\brdrs\brdrw15 \clbrdrl \brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx10872 \pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 r += n\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 X&\cell }\pard \s21\qc\sl280\slmult0 \nowidctlpar\intbl {\f3\fs18\cf1 \{ Distance m = n; \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 if (m >= 0) \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 while (m--) ++r; \par else \par while (m++) --r; \par return r; \}\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard\plain \widctlpar\intbl \f8 {\f3\fs18\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 a + n \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 n + a\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 X\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \{ X tmp = a; \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 return tmp += n; \}\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 a + n == n + a.\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0 \nowidctlpar\intbl \f8 {\f3\fs18\cf1 r -= n\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 X&\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 return r += -n;\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl { \f3\fs18\cf1 \cell }\pard\plain \widctlpar\intbl \f8 {\f3\fs18\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 a - n \par }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 X\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \{ X tmp = a; \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 return tmp -= n; \}\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard\plain \widctlpar\intbl \f8 {\f3\fs18\cf1 \row }\pard\plain \s21\qc\sl280\slmult0 \nowidctlpar\intbl \f8 {\f3\fs18\cf1 b - a\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 Distance\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 pre: there exists a value n of Distance such that a + n = b. \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 b == a + (b - a).\cell }\pard\plain \widctlpar\intbl \f8 {\f3\fs18\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 a[n]\cell }\pard \s21\qc\sl280\slmult0 \nowidctlpar\intbl {\fs20\cf1 convertible to T\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 *(a + n)\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard\plain \widctlpar\intbl \f8 {\f3\fs18\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 a < b\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 convertible to bool\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 b - a > 0\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 < is a total ordering relation\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 a > b\cell }{\fs20\cf1 convertible to bool \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 b < a\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 > }{\fs20\cf1 is a total ordering relation opposite to <.\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 a >= b\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 convertible to bool\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 !(a < b)\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard\plain \widctlpar\intbl \f8 {\f3\fs18\cf1 \row }\trowd \trqc \clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx2808\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx4680\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx7128\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx10872 \pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 a <= b\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 convertible to bool\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl { \f3\fs18\cf1 !(a > b)\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard\plain \widctlpar\intbl \f8 {\f3\fs18\cf1 \row }\pard \qc\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 \par }\pard\plain \s37\ri-548\sb200\sl260\slmult0\nowidctlpar \f8 {\b\f9\fs22\cf1 {\*\bkmkstart _Toc330285531}5.6 Iterator tags}{\f9\fs22\cf1 {\*\bkmkend _Toc330285531} \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 To implement algorithms only in terms of iterators, it is often necessary to infer both of the value type and the distance type from the iterator. To enable this task it is required that for an iterator i of any category other than output it erator, the expression value_type(i) returns (T*)(0) and the expression distance_type(i) returns (Distance*)(0). For output iterators, these expressions are not required. \par }\pard\plain \s40\ri-548\sb160\sl260\slmult0\nowidctlpar \f8 {\i\f9\fs20\cf1 {\*\bkmkstart _Toc330285532}5.6.1 Examples of using iterator tags}{\f9\fs20\cf1 {\*\bkmkend _Toc330285532} \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 For all the regular pointer types we can define value_type and distance_type with the help of: \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 \par }\pard\plain \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar \f8 {\f3\fs18\cf1 template \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 inline T* value_type(const T*) \{ return (T*)(0); \} \par \par template \par inline ptrdiff_t* distance_type(const T*) \{ return (ptrdiff_t*)(0); \} \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 Then, if we want to implement a generic reverse function, we do the following: \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 \par }\pard\plain \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar \f8 {\f3\fs18\cf1 template \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 inline void reverse(BidirectionalIterator first, BidirectionalIterator last) \{ \par \tab __reverse(first, last, value_type(first), distance_type(first)); \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 \} \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 where __reverse is defined as: \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 \par }\pard\plain \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar \f8 {\f3\fs18\cf1 template \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 void __reverse(BidirectionalIterator first, \tab \tab BidirectionalIterator last, \tab \tab T*, \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 \tab \tab Distance*) \{ \par \tab Distance n; \par \tab distance(first, last, n); // see Iterator operations section \par \tab --n; \par \tab while (n > 0) \{ \par \tab \tab T tmp = *first; \par \tab \tab *first++ = *--last; \par \tab \tab *last = tmp; \par \tab \tab n -= 2; \par \tab \} \par \} \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 If there is an additional pointer type __huge such that the difference of two __huge pointers is of the type long long, we define: \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 \par }\pard\plain \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar \f8 {\f3\fs18\cf1 template \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 inline T* value_type(const T __huge *) \{ return (T*)(0); \} \par \par template \par inline long long* distance_type(const T __huge *) \{ return (long long*)(0); \} \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 It is often desirable for a template function to find out what is the most specific category of its iterator argument, so that the funct ion can select the most efficient algorithm at compile time. To facilitate this, the library introduces category tag classes which are used as compile time tags for algorithm selection. They are: input_iterator_tag, output_iterator_tag, forward_iterator_t ag, bidirectional_iterator_tag and random_access_iterator_tag. Every iterator i must have an expression iterator_category(i) defined on it that returns the most specific category tag that describes its behavior. For example, we define that all the pointer types are in the random access iterator category by: \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 \par }\pard\plain \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar \f8 {\f3\fs18\cf1 template \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 inline random_access_iterator_tag iterator_category(const T*) \{ \par \tab return random_access_iterator_tag(); \par \} \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 For a user-defined iterator BinaryTreeIterator, it can be included into the bidirectional iterator category by saying: \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 \par }\pard\plain \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar \f8 {\f3\fs18\cf1 template \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 inline bidirectional_iterator_tag iterator_category( \par \tab \tab const BinaryTreeIterator&) \{ \par \tab return bidirectional_iterator_tag(); \par \} \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 If a template function evolve is well defined for bidirectional iterators, but can be implemented more efficiently for random access iterators, then the implementation is like: \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 \par }\pard\plain \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar \f8 {\f3\fs18\cf1 template \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 inline void evolve(BidirectionalIterator first, BidirectionalIterator last) \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 \tab evolve(first, last, iterator_category(first)); \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 \} \par \par template \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640 {\f3\fs18\cf1 void evolve(BidirectionalIterator first, BidirectionalIterator last, bidirectional_iterator_tag) \{ \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 \tab // ... more generic, but less efficient algorithm \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 \} \par \par template \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640 {\f3\fs18\cf1 void evolve(RandomAccessIterator first, RandomAccessIterator last, \line random_access_iterator_tag) \{ \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 \tab // ... more efficient, but less generic algorithm \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 \} \par }\pard\plain \s40\ri-548\sb160\sl260\slmult0\nowidctlpar \f8 {\i\f9\fs20\cf1 {\*\bkmkstart _Toc330285533}5.6.2 Library defined primitives}{\f9\fs20\cf1 {\*\bkmkend _Toc330285533} \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 To simplify the task of defining the iterator_category, value_type and distance_type for user definable iterators, the library provides the following predefined classes and functions: \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 \par }\pard\plain \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar \f8 {\f3\fs18\cf1 // iterator tags \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 \par struct input_iterator_tag \{\}; \par struct output_iterator_tag \{\}; \par struct forward_iterator_tag \{\}; \par struct bidirectional_iterator_tag \{\}; \par struct random_access_iterator_tag \{\}; \par \par // iterator bases \par \par template struct input_iterator \{\}; \par struct output_iterator \{\}; \par // output_iterator is not a template because output iterators \par // do not have either value type or distance type defined. \par template struct forward_iterator \{\}; \par template struct bidirectional_iterator \{\}; \par template struct random_access_iterator \{\}; \par \par // iterator_category \par \par template \par inline input_iterator_tag \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 iterator_category(const input_iterator&) \{ \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 \tab return input_iterator_tag(); \par \} \par inline output_iterator_tag iterator_category(const output_iterator&) \{ \par \tab return output_iterator_tag(); \par \} \par template \par inline forward_iterator_tag \par iterator_category(const forward_iterator&) \{ \par \tab return forward_iterator_tag(); \par \} \par template \par inline bidirectional_iterator_tag \par iterator_category(const bidirectional_iterator&) \{ \par \tab return bidirectional_iterator_tag(); \par \} \par template \par inline random_access_iterator_tag \par iterator_category(const random_access_iterator&) \{ \par \tab return random_access_iterator_tag(); \par \} \par template \par inline random_access_iterator_tag iterator_category(const T*) \{ \par \tab return random_access_iterator_tag(); \par \} \par \par // value_type of iterator \par \par template \par inline T* value_type(const input_iterator&) \{ \par \tab return (T*)(0); \par \} \par template \par inline T* value_type(const forward_iterator&) \{ \par \tab return (T*)(0); \par \} \par template \par inline T* value_type(const bidirectional_iterator&) \{ \par \tab return (T*)(0); \par \} \par template \par inline T* value_type(const random_access_iterator&) \{ \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 \tab return (T*)(0); \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 \} \par template \par inline T* value_type(const T*) \{ return (T*)(0); \} \par \par // distance_type of iterator \par \par template \par inline Distance* distance_type(const input_iterator&) \{ \par \tab return (Distance*)(0); \par \} \par template \par inline Distance* distance_type(const forward_iterator&) \{ \par \tab return (Distance*)(0); \par \} \par template \par inline Distance* distance_type(const bidirectional_iterator&) \{ \par \tab return (Distance*)(0); \par \} \par template \par inline Distance* distance_type(const random_access_iterator&) \{ \par \tab return (Distance*)(0); \par \} \par template \par inline ptrdiff_t* distance_type(const T*) \{ return (ptrdiff_t*)(0); \} \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 If a user wants to define a bidirectional iterator for some data structure containing double and such that it works on a large memory model of a computer, it can be done by defining: \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 \par }\pard\plain \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar \f8 {\f3\fs18\cf1 class MyIterator : public bidirectional_iterator \{ \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 \tab // code implementing ++, etc. \par \}; \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 Then there is no need to define iterator_category, value_type, and distance_type on MyIterator. \par }\pard\plain \s37\ri-548\sb200\sl260\slmult0\nowidctlpar \f8 {\b\f9\fs22\cf1 {\*\bkmkstart _Toc330285534}5.7 Iterator operations}{\f9\fs22\cf1 {\*\bkmkend _Toc330285534} \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 Since only rand om access iterators provide + and - operators, the library provides two template functions advance and distance. These functions use + and - for random access iterators (and are, therefore, constant time for them); for input, forward and bidirectional ite rators they use ++ to provide linear time implementations. advance takes a negative argument n for random access and bidirectional iterators only. advance increments (or decrements for negative n) iterator reference i by n. distance increments n by the nu mber of times it takes to get from first to last. \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 \par }\pard\plain \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar \f8 {\f3\fs18\cf1 template \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 inline void advance(InputIterator& i, Distance n); \par \par template \par inline void distance(InputIterator first, InputIterator last, Distance& n); \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 distance must be a three argument function storing the result into a reference instead of returning the result because the distance type cannot be deduced from built-in iterator types such as int*. \par }\pard\plain \s34\ri-548\sb320\sl280\slmult0\nowidctlpar \f8 {\b\f9\cf1 {\*\bkmkstart _Toc330285535}6 Function objects}{\f9\cf1 {\*\bkmkend _Toc330285535} \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 Function objects are o bjects with an operator() defined. They are important for the effective use of the library. In the places where one would expect to pass a pointer to a function to an algorithmic template, the interface is specified to accept an object with an operator() defined. This not only makes algorithmic templates work with pointers to functions, but also enables them to work with arbitrary function objects. Using function objects together with function templates increases the expressive power of the library as wel l as making the resulting code much more efficient. For example, if we want to have a by-element addition of two vectors a and b containing double and put the result into a we can do: \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 \par }\pard\plain \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar \f8 {\f3\fs18\cf1 transform(a.begin(), a.end(), b.begin(), a.begin(), plus()); \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 If we want to negate every element of a we can do: \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 \par }\pard\plain \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar \f8 {\f3\fs18\cf1 transform(a.begin(), a.end(), a.begin(), negate()); \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 The corresponding functions will inline the addition and the negation. \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 To enable adaptors and other components to manipulate function objects that t ake one or two arguments it is required that they correspondingly provide typedefs argument_type and result_type for function objects that take one argument and first_argument_type, second_argument_type, and result_type for function objects that take two arguments. \par }\pard\plain \s37\ri-548\sb200\sl260\slmult0\nowidctlpar \f8 {\b\f9\fs22\cf1 {\*\bkmkstart _Toc330285536}6.1 Base}{\f9\fs22\cf1 {\*\bkmkend _Toc330285536} \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 The following classes are provided to simplify the typedefs of the argument and result types: \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 \par }\pard\plain \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar \f8 {\f3\fs18\cf1 template \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 struct unary_function \{ \par \tab typedef Arg argument_type; \par \tab typedef Result result_type; \par \}; \par \par template \par struct binary_function \{ \par \tab typedef Arg1 first_argument_type; \par \tab typedef Arg2 second_argument_type; \par \tab typedef Result result_type; \par \};\tab \par }\pard\plain \s37\ri-548\sb200\sl260\slmult0\nowidctlpar \f8 {\b\f9\fs22\cf1 {\*\bkmkstart _Toc330285537}6.2 Arithmetic operations}{\f9\fs22\cf1 {\*\bkmkend _Toc330285537} \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 The library provides basic function object classes for all of the arithmetic operators in the language. \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 \par }\pard\plain \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar \f8 {\f3\fs18\cf1 template \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 struct plus : binary_function \{ \par \tab T operator()(const T& x, const T& y) const \{ return x + y; \} \par \}; \par \par template \par struct minus : binary_function \{ \par \tab T operator()(const T& x, const T& y) const \{ return x - y; \} \par \}; \par \par template \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 struct times : binary_function \{ \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 \tab T operator()(const T& x, const T& y) const \{ return x * y; \} \par \}; \par \par template \par struct divides : binary_function \{ \par \tab T operator()(const T& x, const T& y) const \{ return x / y; \} \par \}; \par \par template \par struct modulus : binary_function \{ \par \tab T operator()(const T& x, const T& y) const \{ return x % y; \} \par \}; \par \par template \par struct negate : unary_function \{ \par \tab T operator()(const T& x) const \{ return -x; \} \par \}; \par }\pard\plain \s37\ri-548\sb200\sl260\slmult0\nowidctlpar \f8 {\b\f9\fs22\cf1 {\*\bkmkstart _Toc330285538}6.3 Comparisons}{\f9\fs22\cf1 {\*\bkmkend _Toc330285538} \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 The library provides basic function object classes for all of the comparison operators in the language. \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 \par }\pard\plain \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar \f8 {\f3\fs18\cf1 template \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 struct equal_to : binary_function \{ \par \tab bool operator()(const T& x, const T& y) const \{ return x == y; \} \par \}; \par \par template \par struct not_equal_to : binary_function \{ \par \tab bool operator()(const T& x, const T& y) const \{ return x != y; \} \par \}; \par \par template \par struct greater : binary_function \{ \par \tab bool operator()(const T& x, const T& y) const \{ return x > y; \} \par \}; \par \par template \par struct less : binary_function \{ \par \tab bool operator()(const T& x, const T& y) const \{ return x < y; \} \par \}; \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 template \par struct greater_equal : binary_function \{ \par \tab bool operator()(const T& x, const T& y) const \{ return x >= y; \} \par \}; \par \par template \par struct less_equal : binary_function \{ \par \tab bool operator()(const T& x, const T& y) const \{ return x <= y; \} \par \}; \par }\pard\plain \s37\ri-548\sb200\sl260\slmult0\nowidctlpar \f8 {\b\f9\fs22\cf1 {\*\bkmkstart _Toc330285539}6.4 Logical operations}{\f9\fs22\cf1 {\*\bkmkend _Toc330285539} \par }\pard \s37\ri-548\sb200\sl260\slmult0\nowidctlpar {\f9\fs22\cf1 \par }\pard\plain \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar \f8 {\f3\fs18\cf1 template \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 struct logical_and : binary_function \{ \par \tab bool operator()(const T& x, const T& y) const \{ return x && y; \} \par \}; \par \par template \par struct logical_or : binary_function \{ \par \tab bool operator()(const T& x, const T& y) const \{ return x || y; \} \par \}; \par \par template \par struct logical_not : unary_function \{ \par \tab bool operator()(const T& x) const \{ return !x; \} \par \}; \par }\pard\plain \s34\ri-548\sb320\sl280\slmult0\nowidctlpar \f8 {\b\f9\cf1 {\*\bkmkstart _Toc330285540}7 Allocators}{\f9\cf1 {\*\bkmkend _Toc330285540} \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 One of the common problems in portability is to be able to encapsulate the information about the memory model. This information includes the knowl edge of pointer types, the type of their difference, the type of the size of objects in this memory model, as well as the memory allocation and deallocation primitives for it. \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 STL addresses this problem by providing a standard set of requirements for allocators, which are objects that encapsulate this information. All of the containers in STL are parameterized in terms of allocators. That dramatically simplifies the task of dea ling with multiple memory models. \par }\pard\plain \s37\ri-548\sb200\sl260\slmult0\nowidctlpar \f8 {\b\f9\fs22\cf1 {\*\bkmkstart _Toc330285541}7.1 Allocator requirements}{\f9\fs22\cf1 {\*\bkmkend _Toc330285541} \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 In the following tab le, we assume X is an allocator class for objects of type T, a is a value of X, n is of type X::size_type, p is of type X::pointer, r is of type X::reference and s is of type X::const_reference. \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 All the operations on the allocators are expected to be amortized constant time.}{\b\f18\fs20\cf1 \tab }{\b\cf1 Table 7: Allocator requirements \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\cf1 \par }\trowd \trqc \clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrdb\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx3960\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrdb\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx6264\clbrdrt\brdrs\brdrw15 \clbrdrl \brdrs\brdrw15 \clbrdrb\brdrdb\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx11016 \pard \s17\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 expression\cell }\pard \s17\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 return type\cell }\pard \s17\qc\sl280\slmult0 \nowidctlpar\intbl {\fs20\cf1 assertion/note \par }\pard\plain \s21\qj\sl280\slmult0\nowidctlpar\intbl \f8 {\fs20\cf1 pre/post-condition\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\trowd \trqc \clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx3960\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx6264\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx11016 \pard\plain \s21\qc\sl280\slmult0 \nowidctlpar\intbl \f8 {\f3\fs18\cf1 X::value_type \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 T\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard\plain \widctlpar\intbl \f8 {\f3\fs18\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 X::reference\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 lvalue of T\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 \cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 X::const_reference\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 const lvalue of T\cell }\pard \s21\qc\sl280\slmult0 \nowidctlpar\intbl {\fs20\cf1 \cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 X::pointer\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 pointer to T type\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 the result of operator* of values of X::pointer is of reference.\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 X::const_pointer\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 pointer to const T type\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 the result of operator* of values of X::const_pointer is of const_reference; \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 it is the same type of pointer as X::pointer, in particu\-lar, sizeof(X::const_pointer) == sizeof(X::pointer).\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 X::size_type\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 unsigned integral type\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 the type that can represent the size of the largest object in the memory model.\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 X::difference_type\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 signed integral type\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 the type that can represent the difference between any two pointers in the memory model.\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 X a;\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 note: a destructor is assumed.\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 a.address(r)\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 pointer\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 *(a.address(r)) == r.\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 a.const_address(s)\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 const_pointer\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 *(a.address(s)) == s.\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0 \nowidctlpar\intbl \f8 {\f3\fs18\cf1 a.allocate(n)\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 X::pointer\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 memory is allocated for n objects of type T but objects are not constructed. allocate may raise an appropriate exception.\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 a.deallocate(p)\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 result is not used\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 all the objects in the area pointed by p should be destroyed prior to the call of the deallocate.\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 construct(p, a)\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 void\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 post: *p == a.\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 { \f3\fs18\cf1 destroy(p)\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 void\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 the value pointed by p is destroyed.\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 a.init_page_size()\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 X::size_type\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 the returned value is the optimal value for an initial buffer size of the given type. It is assumed that if k is returned by init_page_size, t is the construction time for T, and u is the time that it takes to do allo\- cate(k), then k * t is much greater than u.\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\trowd \trqc \clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx3960\clbrdrt\brdrs\brdrw15 \clbrdrl \brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx6264\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx11016 \pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 a.max_size()\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 X::size_type\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 the largest positive value of X::difference_type\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard \qc\ri-548\sl280\slmult0\nowidctlpar {\fs20\cf1 \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\fs20\cf1 pointer belongs to the category of mutable random access iterators referring to T. const_pointer belongs to the category of constant random a ccess iterators referring to T. There is a conversion defined from pointer to const_pointer. \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\fs20\cf1 For any allocator template Alloc there is a specialization for type void. Alloc has only constructor, destructor, and Alloc::pointer defined. Conversions are defined from any instance of Alloc::pointer into Alloc::pointer and back so that for any p, p == Alloc::pointer(Alloc::pointer(p)). \par }\pard\plain \s37\ri-548\sb200\sl260\slmult0\nowidctlpar \f8 {\b\f9\fs22\cf1 {\*\bkmkstart _Toc330285542}7.2 The default allocator}{\f9\fs22\cf1 {\*\bkmkend _Toc330285542} \par }\pard \s37\ri-548\sb200\sl260\slmult0\nowidctlpar {\f9\fs22\cf1 \par }\pard\plain \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar \f8 {\f3\fs18\cf1 template \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 class allocator \{ \par public: \par \tab typedef T* pointer; \par \tab typedef const T* const_pointer; \par \tab typedef T& reference; \par \tab typedef const T& const_reference; \par \tab typedef T value_type; \par \tab typedef size_t size_type; \par \tab typedef ptrdiff_t difference_type; \par \tab allocator(); \par \tab ~allocator(); \par \tab pointer address(reference x); \par \tab const_pointer const_address(const_reference x); \par \tab pointer allocate(size_type n); \par \tab void deallocate(pointer p); \par \tab size_type init_page_size(); \par \tab size_type max_size(); \par \}; \par \par class allocator \{ \par public: \par \tab typedef void* pointer; \par \tab allocator(); \par \tab ~allocator(); \par \}; \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 In addition to allocator the library vendors are expected to provide allocators for all supported memory models. \par }\pard\plain \s34\ri-548\sb320\sl280\slmult0\nowidctlpar \f8 {\b\f9\cf1 {\*\bkmkstart _Toc330285543}8 Containers}{\f9\cf1 {\*\bkmkend _Toc330285543} \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 Containers are objects that store other objects. They control allocation and deallocation of these objects through constructors, destructors, insert and erase operations. \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 In the following table, we assume X is a container class containing objects of type T, a and b are values of X, u is an identifier and r is a value of X&. \par }\pard \s17\qc\ri-548\sb140\sl280\slmult0\nowidctlpar {\b\cf1 Table 8: Container requirements \par }\pard \s17\qc\ri-548\sb140\sl280\slmult0\nowidctlpar {\cf1 \par }\trowd \trqc \clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrdb\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx3240\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrdb\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx5400\clbrdrt\brdrs\brdrw15 \clbrdrl \brdrs\brdrw15 \clbrdrb\brdrdb\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx7416\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrdb\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx10152\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrdb\brdrw15 \clbrdrr \brdrs\brdrw15 \cellx11016 \pard \s17\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 expression\cell return type\cell }\pard \s17\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 operational semantics\cell }\pard \s17\qc\sl280\slmult0\nowidctlpar\intbl { \fs20\cf1 assertion/note \par }\pard\plain \s21\qj\sl280\slmult0\nowidctlpar\intbl \f8 {\fs20\cf1 pre/post-condition\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 complexity\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\trowd \trqc \clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx3240\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx5400\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx7416\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx10152\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx11016 \pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 X::value_type\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 T\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard \s21\qc\sl280\slmult0 \nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 compile time\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 X::reference\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl { \fs20\cf1 compile time\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 X::const_reference\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 compile \line time\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 X::pointer\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 a pointer type pointing to X::reference\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 pointer to T in the memory model used by the container\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 compile time\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 X::iterator\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 iterator type pointing to X::reference\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 an iterator of any iterator cate\-gory except output iterator.\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 compile time\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 X::const_iterator\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 iterator type pointing to \line X::const_reference\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 a constant iterator of any itera\-tor category except output itera\-tor.\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 compile \line time\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 X::difference_type\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 signed integral type\cell }\pard \s21\qc\sl280\slmult0 \nowidctlpar\intbl {\fs20\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 is identical to the distance type of X::iterator and X::const_iterator\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 compile time\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 X:: \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 size_type\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 unsigned integral type\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 \cell }\pard \s21\qc\sl280\slmult0 \nowidctlpar\intbl {\fs20\cf1 size_type can represent any non-negative value of difference_type\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 compile time\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 X u;\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl { \fs20\cf1 post: u.size() == 0.\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 constant\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 X()\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 X().size() == 0.\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl { \fs20\cf1 constant\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 X(a)\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard \s21\qc\sl280\slmult0 \nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 a == X(a).\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 linear \cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 X u(a); \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 X u = a;\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 X u; u = a;\cell }\pard \s21\qc\sl280\slmult0 \nowidctlpar\intbl {\fs20\cf1 post: u == a.\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 linear\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 (&a)->~X() \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 result is not used\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 post: a.size() == 0. \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 note: the destructor is applied to every element of a and all the memory is returned.\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 linear\cell }\pard\plain \widctlpar\intbl \f8 { \fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 a.begin()\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 iterator; const_iterator for constant a\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl { \fs20\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 constant\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 a.end()\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 iterator; const_iterator for constant a\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl { \fs20\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 constant\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 a == b\cell }{\fs20\cf1 convertible to bool \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 a.size() == b.size() && equal(a.begin(), a.end(), b.begin())\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 == is an equivalence relation. \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 note: equal is defined in the algorithms section.\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 linear\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 a != b\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 convertible to bool\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 !(a == b)\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 linear\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 r = a\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 X&\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 if (&r != &a) \{ \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 (&r)->X::~X(); \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 new (&r) X(a); \par return r; \}\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 post: r == a.\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 linear\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0 \nowidctlpar\intbl \f8 {\f3\fs18\cf1 a.size()\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 size_type\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 size_type n = 0; \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 distance \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 (a.begin(), a.end(), n); \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 return n;\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 constant\cell }\pard\plain \widctlpar\intbl \f8 { \fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 a.max_size()\cell }\pard \s21\qc\fi-1440\li720\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 size_type\cell }\pard \s21\qc\fi-1440\li720\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard \s21\qc\fi-1440\li720\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 size() of the largest possible container.\cell }\pard \s21\qc\fi-1440\li720\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 constant\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\fi-1440\li720\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 a.empty()\cell }\pard \s21\qc\fi-1440\li720\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 convertible to bool\cell }\pard \s21\qc\fi-1440\li720\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 a.size() == 0\cell }\pard \s21\qc\fi-1440\li720\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 constant\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 a < b\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 convertible to bool\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl { \fs20\cf1 lexicographical_compare(a.begin(),a.end(), b.begin(), b.end())\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 pre: < is defined for values of T. \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 < is a total ordering relation. \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 lexicographical_compare is defined in the algorithms sec\-tion.\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 linear\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 a > b\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 convertible to bool\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 b < a\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 linear\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 a <= b \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 convertible to bool\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 !(a > b)\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 \cell }\pard \s21\qc\sl280\slmult0 \nowidctlpar\intbl {\fs20\cf1 linear\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 a >= b\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 convertible to bool \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 !(a < b)\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 linear\cell }\pard\plain \widctlpar\intbl \f8 { \fs20\cf1 \row }\trowd \trqc \clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx3240\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx5400\clbrdrt \brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx7416\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx10152\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb \brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx11016 \pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 a.swap(b)\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 void\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl { \f3\fs18\cf1 swap(a,b)\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 constant\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard \qc\ri-548\sl280\slmult0 \nowidctlpar {\fs20\cf1 \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\fs20\cf1 The member function size() returns the number of elements in the container. Its semantics is defined by the rules of constructors, inserts, and erases. \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\fs20\cf1 begin() returns an iterator referring to the first element in the container. end() returns an iterator which is the past-the-end value. \par If the iterator type of a container belongs to the bidirectional or random access iterator categories, the container is called reversible and satisfies the following additional requirements: \par }\pard \s17\qc\ri-548\sb140\sl280\slmult0\nowidctlpar {\b\cf1 Table 9: Reversible container requirements (in addition to container) \par }\pard \s17\qc\ri-548\sb140\sl280\slmult0\nowidctlpar {\cf1 \par }\trowd \trqc \clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrdb\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx3240\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrdb\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx5400\clbrdrt\brdrs\brdrw15 \clbrdrl \brdrs\brdrw15 \clbrdrb\brdrdb\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx10152\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrdb\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx11016 \pard \s17\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 expression\cell }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\fs20\cf1 return type\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 operational semantics\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 complexity\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\trowd \trqc \clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx3240\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr \brdrs\brdrw15 \cellx5400\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx10152\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx11016 \pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 X::reverse_iterator\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 reverse_iterator \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 for random access iterator \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 reverse_bidirectional_iterator \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 for bidirectional iterator\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 compile \line time\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 X::const_reverse_iterator\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 reverse_iterator \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 for random access iterator \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 reverse_bidirectional_iterator< \par const_iterator, value_type, \par const_reference, difference_type> \par }{\fs20\cf1 for bidirectional iterator\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 compile \line time\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 a.rbegin()\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 reverse_iterator; \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 const_reverse_iterator for constant a\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 reverse_iterator(end())\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 constant\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\trowd \trqc \clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx3240\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx5400\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx10152\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx11016 \pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 a.rend()\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 reverse_iterator; \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 const_reverse_iterator for constant a\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 reverse_iterator(begin())\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 constant\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard \qc\ri-548\sl280\slmult0\nowidctlpar {\fs20\cf1 \par }\pard\plain \s37\ri-548\sb200\sl260\slmult0\nowidctlpar \f8 {\b\f9\fs22\cf1 {\*\bkmkstart _Toc330285544}8.1 Sequences}{\f9\fs22\cf1 {\*\bkmkend _Toc330285544} \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 A sequence is a kind of container that organizes a finite set of objects, all of the same type, into a strictly linea r arrangement. The library provides three basic kinds of sequence containers: vector, list, and deque. It also provides container adaptors that make it easy to construct abstract data types, such as stacks or queues, out of the basic sequence kinds (or ou t of other kinds of sequences that the user might define). \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 In the following two tables, X is a sequence class, a is value of X, i and j satisfy input iterator requirements, [i, j) is a valid range, n is a value of X::size_type, p is a valid iterator to a, q is a dereferenceable iterator to a, [q1, q2) is a valid range in a, t is a value of X::value_type. \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 The complexities of the expressions are sequence dependent. \par }\pard \s17\qc\ri-548\sb140\sl280\slmult0\nowidctlpar {\b\cf1 Table 10: Sequence requirements (in addition to container) \par }\pard \s17\qc\ri-548\sb140\sl280\slmult0\nowidctlpar {\cf1 \par }\trowd \trqc \clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrdb\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx3960\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrdb\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx5688\clbrdrt\brdrs\brdrw15 \clbrdrl \brdrs\brdrw15 \clbrdrb\brdrdb\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx10296 \pard \s17\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 expression\cell }\pard \s17\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 return type\cell }\pard \s17\qc\sl280\slmult0 \nowidctlpar\intbl {\fs20\cf1 assertion/note \par }\pard\plain \s21\qj\sl280\slmult0\nowidctlpar\intbl \f8 {\fs20\cf1 pre/post-condition\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\trowd \trqc \clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx3960\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx5688\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx10296 \pard\plain \s21\qc\sl280\slmult0 \nowidctlpar\intbl \f8 {\f3\fs18\cf1 X(n, t) \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 X a(n, t);\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 post: size() == n. \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 constructs a sequence with n copies of t.\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 X(i, j) \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 X a(i, j);\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 \cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 post: size() == distance between i and j. \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 constructs a sequence equal to the range [i, j).\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 a.insert(p, t)\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 iterator\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 inserts a copy of t before p. \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 the return value points to the inserted copy.\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 a.insert(p, n, t)\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 result is not used\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 inserts n copies of t before p.\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 a.insert(p, i, j)\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 result is not used\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 inserts copies of elements in [i, j) before p.\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 a.erase(q)\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 result is not used\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 erases the element pointed to by q.\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\trowd \trqc \clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb \brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx3960\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx5688\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx10296 \pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 a.erase(q1, q2)\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 result is not used\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 erases the elements in the range [q1, q2).\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard \qc\ri-548\sl280\slmult0\nowidctlpar {\fs20\cf1 \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\fs20\cf1 vector, list, and deque offer the programmer different complexity trade-offs and should be used accordingly. vector is the type of sequence that shou ld be used by default. list should be used when there are frequent insertions and deletions from the middle of the sequence. deque is the data structure of choice when most insertions and deletions take place at the beginning or at the end of the sequence . \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\fs20\cf1 iterator and const_iterator types for sequences have to be at least of the forward iterator category. \par }\pard \s17\qc\ri-548\sb140\sl280\slmult0\nowidctlpar {\b\cf1 Table 11: Optional sequence operations \par }\pard \s17\qc\ri-548\sb140\sl280\slmult0\nowidctlpar {\cf1 \par }\trowd \trqc \clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrdb\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx3672\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrdb\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx5976\clbrdrt\brdrs\brdrw15 \clbrdrl \brdrs\brdrw15 \clbrdrb\brdrdb\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx8712\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrdb\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx10872 \pard \s17\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 expression\cell }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\fs20\cf1 return type\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 operational semantics\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 container\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\trowd \trqc \clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx3672\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr \brdrs\brdrw15 \cellx5976\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx8712\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx10872 \pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 a.front()\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 reference; \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 const_reference for constant a\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 *a.begin()\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 vector, list, deque\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 a.back()\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 reference; \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 const_reference for constant a\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 *a.(--end())\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 vector, list, deque \cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 a.push_front(t)\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 void\cell }\pard \s21\qc\sl280\slmult0 \nowidctlpar\intbl {\f3\fs18\cf1 a.insert(a.begin(), t)\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 list, deque\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 { \f3\fs18\cf1 a.push_back(t)\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 void\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 a.insert(a.end(), t)\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 vector, list, deque\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 a.pop_front()\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 void\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 a.erase(a.begin())\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 list, deque\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard\plain \s21\qc\sl280\slmult0 \nowidctlpar\intbl \f8 {\f3\fs18\cf1 a.pop_back()\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 void\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 a.erase(--a.end())\cell }\pard \s21\qc\sl280\slmult0 \nowidctlpar\intbl {\fs20\cf1 vector, list, deque\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\trowd \trqc \clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx3672\clbrdrt\brdrs\brdrw15 \clbrdrl \brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx5976\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr\brdrs\brdrw15 \cellx8712\clbrdrt\brdrs\brdrw15 \clbrdrl\brdrs\brdrw15 \clbrdrb\brdrs\brdrw15 \clbrdrr \brdrs\brdrw15 \cellx10872 \pard\plain \s21\qc\sl280\slmult0\nowidctlpar\intbl \f8 {\f3\fs18\cf1 a[n]\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 reference; \par }\pard \s21\qj\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 const_reference for constant a\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\f3\fs18\cf1 *(a.begin() + n)\cell }\pard \s21\qc\sl280\slmult0\nowidctlpar\intbl {\fs20\cf1 vector, deque\cell }\pard\plain \widctlpar\intbl \f8 {\fs20\cf1 \row }\pard \qc\ri-548\sl280\slmult0\nowidctlpar {\fs20\cf1 \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\fs20\cf1 All the operations in the above table are provided only for the containers for which they take constant time. \par }\pard\plain \s40\ri-548\sb160\sl260\slmult0\nowidctlpar \f8 {\i\f9\fs20\cf1 {\*\bkmkstart _Toc330285545}8.1.1 Vector}{\f9\fs20\cf1 {\*\bkmkend _Toc330285545} \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 vector is a kind of sequence that supports random access iterators. In addition, it supports (amortized) constant time insert and erase operations at the end; insert and erase in the middle take linear time. Storage management is handled automatically, th ough hints can be given to improve efficiency. \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 \par }\pard\plain \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar \f8 {\f3\fs18\cf1 template class Allocator = allocator> \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 class vector \{ \par public: \par \par // typedefs: \par \par \tab typedef iterator; \par \tab typedef const_iterator; \par \tab typedef Allocator::pointer pointer; \par \tab typedef Allocator::reference reference; \par \tab typedef Allocator::const_reference const_reference; \par \tab typedef size_type; \par \tab typedef difference_type; \par \tab typedef T value_type; \par \tab typedef reverse_iterator; \par \tab typedef const_reverse_iterator; \par \par // allocation/deallocation: \par \par \tab vector(); \par \tab vector(size_type n, const T& value = T()); \par \tab vector(const vector& x); \par \tab template \par \tab vector(InputIterator first, InputIterator last); \par \tab ~vector(); \par \tab vector& operator=(const vector& x); \par \tab void reserve(size_type n); \par \tab void swap(vector& x); \par \par // accessors: \par \par \tab iterator begin(); \par \tab const_iterator begin() const; \par \tab iterator end(); \par \tab const_iterator end() const; \par \tab reverse_iterator rbegin(); \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 \tab const_reverse_iterator rbegin(); \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 \tab reverse_iterator rend(); \par \tab const_reverse_iterator rend(); \par \tab size_type size() const; \par \tab size_type max_size() const; \par \tab size_type capacity() const; \par \tab bool empty() const; \par \tab reference operator[](size_type n); \par \tab const_reference operator[](size_type n) const; \par \tab reference front(); \par \tab const_reference front() const; \par \tab reference back(); \par \tab const_reference back() const; \par \par // insert/erase: \par \par \tab void push_back(const T& x); \par \tab iterator insert(iterator position, const T& x = T()); \par \tab void insert(iterator position, size_type n, const T& x); \par \tab template \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 \tab void insert(iterator position, InputIterator first, InputIterator last); \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 \tab void pop_back(); \par \tab void erase(iterator position); \par \tab void erase(iterator first, iterator last); \par \}; \par \par template \par bool operator==(const vector& x, const vector& y); \par \par template \par bool operator<(const vector& x, const vector& y); \par \tab \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 iterator is a random access iterator \tab referring to T. The exact type is implementation dependent and determined by Allocator. \tab \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 const_iterator is a constant random access iterator referring to const T.\tab The exact type is implementation dependent and determined by Allocator. I t is guaranteed that there is a constructor for const_iterator out of iterator. \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 \tab \tab size_type is an unsigned integral type. The exact type is implementation dependent and determined by Allocator. \par \tab difference_type is a signed integral type. The exact type is implementation dependent and determined by Allocator. \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 The constructor template \tab vector(InputIterator first, InputIterator last) makes only N calls to the copy constructor of T (where N is the distance between first and last) and no re allocations if iterators first and last are of forward, bidirectional, or random access categories. It does at most 2N calls to the copy constructor of T and logN reallocations if they are just input iterators, since it is impossible to determine the dist ance between first and last and then do copying. \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 The member function capacity returns the size of the allocated storage in the vector. The member function reserve is a directive that informs vector of a planned change in size, so that it can manage the stor age allocation accordingly. It does not change the size of the sequence and takes at most linear time in the size of the sequence. Reallocation happens at this point if and only if the current capacity is less than the argument of reserve. After reserve, capacity is greater or equal to the argument of reserve if reallocation happens; and equal to the previous value of capacity otherwise. Reallocation invalidates all the references, pointers, and iterators referring to the elements in the sequence. It is g uaranteed that no reallocation takes place during the insertions that happen after reserve takes place till the time when the size of the vector reaches the size specified by reserve. \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 insert causes reallocation if the new size is greater than the old capacity. If no reallocation happens, all the iterators and references before the insertion point remain valid. Inserting a single element into a vector is linear in the distance from the insertion point to the end of the vector. The amortized complexity over the lifetime of a vector of inserting a single element at its end is constant. Insertion of multiple elements into a vector with a single call of the insert member function is linear in the sum of the number of elements plus the distance to the end of the ve ctor. In other words, it is much faster to insert many elements into the middle of a vector at once than to do the insertion one at a time. The insert template member function preallocates enough storage for the insertion if the iterators first and last a re of forward, bidirectional or random access category. Otherwise, it does insert elements one by one and should not be used for inserting into the middle of vectors. \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 erase invalidates all the iterators and references after the point of the erase. The destructor of T is called the number of times equal to the number of the elements erased, but the assignment operator of T is called the number of times equal to the numb er of elements in the vector after the erased elements. \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 To optimize space allocation, a specialization for bool is provided: \par }\pard \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar {\f18\fs20\cf1 \par }\pard\plain \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar \f8 {\f3\fs18\cf1 class vector \{ \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 public: \par \par // bit reference: \par \par \tab class reference \{ \par \tab public: \par \tab \tab ~reference(); \par \tab \tab operator bool() const; \par \tab \tab reference& operator=(const bool x); \par \tab \tab void flip();\tab \tab \tab // flips the bit \par \tab \}; \par \par // typedefs: \par \par \tab typedef bool const_reference; \par \tab typedef iterator; \par \tab typedef const_iterator; \par \tab typedef size_t size_type; \par \tab typedef ptrdiff_t difference_type; \par \tab typedef bool value_type; \par \tab typedef reverse_iterator; \par \tab typedef const_reverse_iterator; \par \par // allocation/deallocation: \par \par \tab vector(); \par \tab vector(size_type n, const bool& value = bool()); \par \tab vector(const vector& x); \par \tab template \par \tab vector(InputIterator first, InputIterator last); \par \tab ~vector(); \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 \tab vector& operator=(const vector& x); \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 \tab void reserve(size_type n); \par \tab void swap(vector& x); \par \par // accessors: \par \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 \tab iterator begin(); \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 \tab const_iterator begin() const; \par \tab iterator end(); \par \tab const_iterator end() const; \par \tab reverse_iterator rbegin(); \par \tab const_reverse_iterator rbegin(); \par \tab reverse_iterator rend(); \par \tab const_reverse_iterator rend(); \par \tab size_type size() const; \par \tab size_type max_size() const; \par \tab size_type capacity() const; \par \tab bool empty() const; \par \tab reference operator[](size_type n); \par \tab const_reference operator[](size_type n) const; \par \tab reference front(); \par \tab const_reference front() const; \par \tab reference back(); \par \tab const_reference back() const; \par \par // insert/erase: \par \par \tab void push_back(const bool& x); \par \tab iterator insert(iterator position, const bool& x = bool()); \par \tab void insert (iterator position, size_type n, const bool& x); \par \tab template \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 \tab void insert (iterator position, InputIterator first, InputIterator last); \par }\pard \s32\fi-1440\li2160\ri-548\sl280\slmult0\nowidctlpar {\f3\fs18\cf1 \tab void pop_back(); \par \tab void erase(iterator position); \par \tab void erase(iterator first, iterator last); \par \}; \par \par void swap(vector::reference x, \par \tab vector::reference y); \par \par bool operator==(const vector& x, \par \tab \tab const vector& y); \par \par bool operator<(const vector& x, \par \tab \tab const vector& y); \par }\pard\plain \s17\qj\ri-548\sb140\sl280\slmult0\nowidctlpar \f8 {\f18\fs20\cf1 reference is a class that simulates the behavior of references of a single bit in vector. \par Every implementation is expected to provide specializations of vector for all supported memory models. \par }\pard \s17\sb140\sl280\slmult0\nowidctlpar\pvpg\phpg\posx532\posy144\absh2563\absw8280 {\f18\fs20\cf1 At present, it is not possible to templatize a specialization. That is, we cannot write: \par }\pard \s17\sb140\sl280\slmult0\nowidctlpar\pvpg\phpg\posx532\posy144\absh2563\absw8280 {\f18\fs20\cf1 \par }\pard\plain \s32\fi-1440\li2160\sl280\slmult0\nowidctlpar\pvpg\phpg\posx532\posy144\absh2563\absw8280 \f8 {\f3\fs18\cf1 template