facade-and-adaptor.html 157 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <meta name="generator" content="Docutils 0.5: http://docutils.sourceforge.net/" />
  7. <title>Iterator Facade and Adaptor</title>
  8. <meta name="author" content="David Abrahams, Jeremy Siek, Thomas Witt" />
  9. <meta name="organization" content="Boost Consulting, Indiana University Open Systems Lab, Zephyr Associates, Inc." />
  10. <meta name="date" content="2006-09-11" />
  11. <link rel="stylesheet" href="../../../rst.css" type="text/css" />
  12. </head>
  13. <body>
  14. <div class="document" id="iterator-facade-and-adaptor">
  15. <h1 class="title">Iterator Facade and Adaptor</h1>
  16. <table class="docinfo" frame="void" rules="none">
  17. <col class="docinfo-name" />
  18. <col class="docinfo-content" />
  19. <tbody valign="top">
  20. <tr><th class="docinfo-name">Author:</th>
  21. <td>David Abrahams, Jeremy Siek, Thomas Witt</td></tr>
  22. <tr><th class="docinfo-name">Contact:</th>
  23. <td><a class="first reference external" href="mailto:dave&#64;boost-consulting.com">dave&#64;boost-consulting.com</a>, <a class="reference external" href="mailto:jsiek&#64;osl.iu.edu">jsiek&#64;osl.iu.edu</a>, <a class="last reference external" href="mailto:witt&#64;styleadvisor.com">witt&#64;styleadvisor.com</a></td></tr>
  24. <tr><th class="docinfo-name">Organization:</th>
  25. <td><a class="first reference external" href="http://www.boost-consulting.com">Boost Consulting</a>, Indiana University <a class="reference external" href="http://www.osl.iu.edu">Open Systems
  26. Lab</a>, <a class="last reference external" href="http://www.styleadvisor.com">Zephyr Associates, Inc.</a></td></tr>
  27. <tr><th class="docinfo-name">Date:</th>
  28. <td>2006-09-11</td></tr>
  29. <tr class="field"><th class="docinfo-name">Number:</th><td class="field-body">This is a revised version of <a class="reference external" href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1530.html">N1530</a>=03-0113, which was
  30. accepted for Technical Report 1 by the C++ standard
  31. committee's library working group.</td>
  32. </tr>
  33. </tbody>
  34. </table>
  35. <!-- Distributed under the Boost -->
  36. <!-- Software License, Version 1.0. (See accompanying -->
  37. <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
  38. <!-- Version 1.9 of this ReStructuredText document corresponds to
  39. n1530_, the paper accepted by the LWG. -->
  40. <table class="docutils field-list" frame="void" rules="none">
  41. <col class="field-name" />
  42. <col class="field-body" />
  43. <tbody valign="top">
  44. <tr class="field"><th class="field-name">copyright:</th><td class="field-body">Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003.</td>
  45. </tr>
  46. </tbody>
  47. </table>
  48. <table class="docutils field-list" frame="void" rules="none">
  49. <col class="field-name" />
  50. <col class="field-body" />
  51. <tbody valign="top">
  52. <tr class="field"><th class="field-name">abstract:</th><td class="field-body">We propose a set of class templates that help programmers
  53. build standard-conforming iterators, both from scratch and
  54. by adapting other iterators.</td>
  55. </tr>
  56. </tbody>
  57. </table>
  58. <div class="contents topic" id="table-of-contents">
  59. <p class="topic-title first">Table of Contents</p>
  60. <ul class="simple">
  61. <li><a class="reference internal" href="#motivation" id="id15">Motivation</a></li>
  62. <li><a class="reference internal" href="#impact-on-the-standard" id="id16">Impact on the Standard</a></li>
  63. <li><a class="reference internal" href="#design" id="id17">Design</a><ul>
  64. <li><a class="reference internal" href="#iterator-concepts" id="id18">Iterator Concepts</a></li>
  65. <li><a class="reference internal" href="#interoperability" id="id19">Interoperability</a></li>
  66. <li><a class="reference internal" href="#iterator-facade" id="id20">Iterator Facade</a><ul>
  67. <li><a class="reference internal" href="#usage" id="id21">Usage</a></li>
  68. <li><a class="reference internal" href="#iterator-core-access" id="id22">Iterator Core Access</a></li>
  69. <li><a class="reference internal" href="#operator" id="id23"><tt class="docutils literal"><span class="pre">operator[]</span></tt></a></li>
  70. <li><a class="reference internal" href="#id6" id="id24"><tt class="docutils literal"><span class="pre">operator-&gt;</span></tt></a></li>
  71. </ul>
  72. </li>
  73. <li><a class="reference internal" href="#iterator-adaptor" id="id25">Iterator Adaptor</a></li>
  74. <li><a class="reference internal" href="#specialized-adaptors" id="id26">Specialized Adaptors</a></li>
  75. </ul>
  76. </li>
  77. <li><a class="reference internal" href="#proposed-text" id="id27">Proposed Text</a><ul>
  78. <li><a class="reference internal" href="#header-iterator-helper-synopsis-lib-iterator-helper-synopsis" id="id28">Header <tt class="docutils literal"><span class="pre">&lt;iterator_helper&gt;</span></tt> synopsis [lib.iterator.helper.synopsis]</a></li>
  79. <li><a class="reference internal" href="#iterator-facade-lib-iterator-facade" id="id29">Iterator facade [lib.iterator.facade]</a><ul>
  80. <li><a class="reference internal" href="#class-template-iterator-facade" id="id30">Class template <tt class="docutils literal"><span class="pre">iterator_facade</span></tt></a></li>
  81. <li><a class="reference internal" href="#iterator-facade-requirements" id="id31"><tt class="docutils literal"><span class="pre">iterator_facade</span></tt> Requirements</a></li>
  82. <li><a class="reference internal" href="#iterator-facade-operations" id="id32"><tt class="docutils literal"><span class="pre">iterator_facade</span></tt> operations</a></li>
  83. </ul>
  84. </li>
  85. <li><a class="reference internal" href="#iterator-adaptor-lib-iterator-adaptor" id="id33">Iterator adaptor [lib.iterator.adaptor]</a><ul>
  86. <li><a class="reference internal" href="#class-template-iterator-adaptor" id="id34">Class template <tt class="docutils literal"><span class="pre">iterator_adaptor</span></tt></a></li>
  87. <li><a class="reference internal" href="#iterator-adaptor-requirements" id="id35"><tt class="docutils literal"><span class="pre">iterator_adaptor</span></tt> requirements</a></li>
  88. <li><a class="reference internal" href="#iterator-adaptor-base-class-parameters" id="id36"><tt class="docutils literal"><span class="pre">iterator_adaptor</span></tt> base class parameters</a></li>
  89. <li><a class="reference internal" href="#iterator-adaptor-public-operations" id="id37"><tt class="docutils literal"><span class="pre">iterator_adaptor</span></tt> public operations</a></li>
  90. <li><a class="reference internal" href="#iterator-adaptor-protected-member-functions" id="id38"><tt class="docutils literal"><span class="pre">iterator_adaptor</span></tt> protected member functions</a></li>
  91. <li><a class="reference internal" href="#iterator-adaptor-private-member-functions" id="id39"><tt class="docutils literal"><span class="pre">iterator_adaptor</span></tt> private member functions</a></li>
  92. </ul>
  93. </li>
  94. <li><a class="reference internal" href="#specialized-adaptors-lib-iterator-special-adaptors" id="id40">Specialized adaptors [lib.iterator.special.adaptors]</a><ul>
  95. <li><a class="reference internal" href="#indirect-iterator" id="id41">Indirect iterator</a><ul>
  96. <li><a class="reference internal" href="#class-template-pointee" id="id42">Class template <tt class="docutils literal"><span class="pre">pointee</span></tt></a></li>
  97. <li><a class="reference internal" href="#class-template-indirect-reference" id="id43">Class template <tt class="docutils literal"><span class="pre">indirect_reference</span></tt></a></li>
  98. <li><a class="reference internal" href="#class-template-indirect-iterator" id="id44">Class template <tt class="docutils literal"><span class="pre">indirect_iterator</span></tt></a></li>
  99. <li><a class="reference internal" href="#indirect-iterator-requirements" id="id45"><tt class="docutils literal"><span class="pre">indirect_iterator</span></tt> requirements</a></li>
  100. <li><a class="reference internal" href="#indirect-iterator-models" id="id46"><tt class="docutils literal"><span class="pre">indirect_iterator</span></tt> models</a></li>
  101. <li><a class="reference internal" href="#indirect-iterator-operations" id="id47"><tt class="docutils literal"><span class="pre">indirect_iterator</span></tt> operations</a></li>
  102. </ul>
  103. </li>
  104. <li><a class="reference internal" href="#reverse-iterator" id="id48">Reverse iterator</a><ul>
  105. <li><a class="reference internal" href="#class-template-reverse-iterator" id="id49">Class template <tt class="docutils literal"><span class="pre">reverse_iterator</span></tt></a></li>
  106. <li><a class="reference internal" href="#reverse-iterator-requirements" id="id50"><tt class="docutils literal"><span class="pre">reverse_iterator</span></tt> requirements</a></li>
  107. <li><a class="reference internal" href="#reverse-iterator-models" id="id51"><tt class="docutils literal"><span class="pre">reverse_iterator</span></tt> models</a></li>
  108. <li><a class="reference internal" href="#reverse-iterator-operations" id="id52"><tt class="docutils literal"><span class="pre">reverse_iterator</span></tt> operations</a></li>
  109. </ul>
  110. </li>
  111. <li><a class="reference internal" href="#transform-iterator" id="id53">Transform iterator</a><ul>
  112. <li><a class="reference internal" href="#class-template-transform-iterator" id="id54">Class template <tt class="docutils literal"><span class="pre">transform_iterator</span></tt></a></li>
  113. <li><a class="reference internal" href="#transform-iterator-requirements" id="id55"><tt class="docutils literal"><span class="pre">transform_iterator</span></tt> requirements</a></li>
  114. <li><a class="reference internal" href="#transform-iterator-models" id="id56"><tt class="docutils literal"><span class="pre">transform_iterator</span></tt> models</a></li>
  115. <li><a class="reference internal" href="#transform-iterator-operations" id="id57"><tt class="docutils literal"><span class="pre">transform_iterator</span></tt> operations</a></li>
  116. </ul>
  117. </li>
  118. <li><a class="reference internal" href="#filter-iterator" id="id58">Filter iterator</a><ul>
  119. <li><a class="reference internal" href="#class-template-filter-iterator" id="id59">Class template <tt class="docutils literal"><span class="pre">filter_iterator</span></tt></a></li>
  120. <li><a class="reference internal" href="#filter-iterator-requirements" id="id60"><tt class="docutils literal"><span class="pre">filter_iterator</span></tt> requirements</a></li>
  121. <li><a class="reference internal" href="#filter-iterator-models" id="id61"><tt class="docutils literal"><span class="pre">filter_iterator</span></tt> models</a></li>
  122. <li><a class="reference internal" href="#filter-iterator-operations" id="id62"><tt class="docutils literal"><span class="pre">filter_iterator</span></tt> operations</a></li>
  123. </ul>
  124. </li>
  125. <li><a class="reference internal" href="#counting-iterator" id="id63">Counting iterator</a><ul>
  126. <li><a class="reference internal" href="#class-template-counting-iterator" id="id64">Class template <tt class="docutils literal"><span class="pre">counting_iterator</span></tt></a></li>
  127. <li><a class="reference internal" href="#counting-iterator-requirements" id="id65"><tt class="docutils literal"><span class="pre">counting_iterator</span></tt> requirements</a></li>
  128. <li><a class="reference internal" href="#counting-iterator-models" id="id66"><tt class="docutils literal"><span class="pre">counting_iterator</span></tt> models</a></li>
  129. <li><a class="reference internal" href="#counting-iterator-operations" id="id67"><tt class="docutils literal"><span class="pre">counting_iterator</span></tt> operations</a></li>
  130. </ul>
  131. </li>
  132. <li><a class="reference internal" href="#function-output-iterator" id="id68">Function output iterator</a><ul>
  133. <li><a class="reference internal" href="#class-template-function-output-iterator" id="id69">Class template <tt class="docutils literal"><span class="pre">function_output_iterator</span></tt></a></li>
  134. <li><a class="reference internal" href="#header" id="id70">Header</a></li>
  135. <li><a class="reference internal" href="#function-output-iterator-requirements" id="id71"><tt class="docutils literal"><span class="pre">function_output_iterator</span></tt> requirements</a></li>
  136. <li><a class="reference internal" href="#function-output-iterator-models" id="id72"><tt class="docutils literal"><span class="pre">function_output_iterator</span></tt> models</a></li>
  137. <li><a class="reference internal" href="#function-output-iterator-operations" id="id73"><tt class="docutils literal"><span class="pre">function_output_iterator</span></tt> operations</a></li>
  138. </ul>
  139. </li>
  140. </ul>
  141. </li>
  142. </ul>
  143. </li>
  144. </ul>
  145. </div>
  146. <div class="section" id="motivation">
  147. <h1><a class="toc-backref" href="#id15">Motivation</a></h1>
  148. <p>Iterators play an important role in modern C++ programming. The
  149. iterator is the central abstraction of the algorithms of the Standard
  150. Library, allowing algorithms to be re-used in in a wide variety of
  151. contexts. The C++ Standard Library contains a wide variety of useful
  152. iterators. Every one of the standard containers comes with constant
  153. and mutable iterators<a class="footnote-reference" href="#mutable" id="id1"><sup>2</sup></a>, and also reverse versions of those
  154. same iterators which traverse the container in the opposite direction.
  155. The Standard also supplies <tt class="docutils literal"><span class="pre">istream_iterator</span></tt> and
  156. <tt class="docutils literal"><span class="pre">ostream_iterator</span></tt> for reading from and writing to streams,
  157. <tt class="docutils literal"><span class="pre">insert_iterator</span></tt>, <tt class="docutils literal"><span class="pre">front_insert_iterator</span></tt> and
  158. <tt class="docutils literal"><span class="pre">back_insert_iterator</span></tt> for inserting elements into containers, and
  159. <tt class="docutils literal"><span class="pre">raw_storage_iterator</span></tt> for initializing raw memory [7].</p>
  160. <p>Despite the many iterators supplied by the Standard Library, obvious
  161. and useful iterators are missing, and creating new iterator types is
  162. still a common task for C++ programmers. The literature documents
  163. several of these, for example line_iterator [3] and Constant_iterator
  164. [9]. The iterator abstraction is so powerful that we expect
  165. programmers will always need to invent new iterator types.</p>
  166. <p>Although it is easy to create iterators that <em>almost</em> conform to the
  167. standard, the iterator requirements contain subtleties which can make
  168. creating an iterator which <em>actually</em> conforms quite difficult.
  169. Further, the iterator interface is rich, containing many operators
  170. that are technically redundant and tedious to implement. To automate
  171. the repetitive work of constructing iterators, we propose
  172. <tt class="docutils literal"><span class="pre">iterator_facade</span></tt>, an iterator base class template which provides
  173. the rich interface of standard iterators and delegates its
  174. implementation to member functions of the derived class. In addition
  175. to reducing the amount of code necessary to create an iterator, the
  176. <tt class="docutils literal"><span class="pre">iterator_facade</span></tt> also provides compile-time error detection.
  177. Iterator implementation mistakes that often go unnoticed are turned
  178. into compile-time errors because the derived class implementation must
  179. match the expectations of the <tt class="docutils literal"><span class="pre">iterator_facade</span></tt>.</p>
  180. <p>A common pattern of iterator construction is the adaptation of one
  181. iterator to form a new one. The functionality of an iterator is
  182. composed of four orthogonal aspects: traversal, indirection, equality
  183. comparison and distance measurement. Adapting an old iterator to
  184. create a new one often saves work because one can reuse one aspect of
  185. functionality while redefining the other. For example, the Standard
  186. provides <tt class="docutils literal"><span class="pre">reverse_iterator</span></tt>, which adapts any Bidirectional Iterator
  187. by inverting its direction of traversal. As with plain iterators,
  188. iterator adaptors defined outside the Standard have become commonplace
  189. in the literature:</p>
  190. <ul class="simple">
  191. <li>Checked iter[13] adds bounds-checking to an existing iterator.</li>
  192. <li>The iterators of the View Template Library[14], which adapts
  193. containers, are themselves adaptors over the underlying iterators.</li>
  194. <li>Smart iterators [5] adapt an iterator's dereferencing behavior by
  195. applying a function object to the object being referenced and
  196. returning the result.</li>
  197. <li>Custom iterators [4], in which a variety of adaptor types are enumerated.</li>
  198. <li>Compound iterators [1], which access a slice out of a container of containers.</li>
  199. <li>Several iterator adaptors from the MTL [12]. The MTL contains a
  200. strided iterator, where each call to <tt class="docutils literal"><span class="pre">operator++()</span></tt> moves the
  201. iterator ahead by some constant factor, and a scaled iterator, which
  202. multiplies the dereferenced value by some constant.</li>
  203. </ul>
  204. <table class="docutils footnote" frame="void" id="concept" rules="none">
  205. <colgroup><col class="label" /><col /></colgroup>
  206. <tbody valign="top">
  207. <tr><td class="label">[1]</td><td>We use the term concept to mean a set of requirements
  208. that a type must satisfy to be used with a particular template
  209. parameter.</td></tr>
  210. </tbody>
  211. </table>
  212. <table class="docutils footnote" frame="void" id="mutable" rules="none">
  213. <colgroup><col class="label" /><col /></colgroup>
  214. <tbody valign="top">
  215. <tr><td class="label"><a class="fn-backref" href="#id1">[2]</a></td><td>The term mutable iterator refers to iterators over objects that
  216. can be changed by assigning to the dereferenced iterator, while
  217. constant iterator refers to iterators over objects that cannot be
  218. modified.</td></tr>
  219. </tbody>
  220. </table>
  221. <p>To fulfill the need for constructing adaptors, we propose the
  222. <tt class="docutils literal"><span class="pre">iterator_adaptor</span></tt> class template. Instantiations of
  223. <tt class="docutils literal"><span class="pre">iterator_adaptor</span></tt> serve as a base classes for new iterators,
  224. providing the default behavior of forwarding all operations to the
  225. underlying iterator. The user can selectively replace these features
  226. in the derived iterator class. This proposal also includes a number
  227. of more specialized adaptors, such as the <tt class="docutils literal"><span class="pre">transform_iterator</span></tt> that
  228. applies some user-specified function during the dereference of the
  229. iterator.</p>
  230. </div>
  231. <div class="section" id="impact-on-the-standard">
  232. <h1><a class="toc-backref" href="#id16">Impact on the Standard</a></h1>
  233. <p>This proposal is purely an addition to the C++ standard library.
  234. However, note that this proposal relies on the proposal for New
  235. Iterator Concepts.</p>
  236. </div>
  237. <div class="section" id="design">
  238. <h1><a class="toc-backref" href="#id17">Design</a></h1>
  239. <div class="section" id="iterator-concepts">
  240. <h2><a class="toc-backref" href="#id18">Iterator Concepts</a></h2>
  241. <p>This proposal is formulated in terms of the new <tt class="docutils literal"><span class="pre">iterator</span> <span class="pre">concepts</span></tt>
  242. as proposed in <a class="reference external" href="http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2003/n1550.htm">n1550</a>, since user-defined and especially adapted
  243. iterators suffer from the well known categorization problems that are
  244. inherent to the current iterator categories.</p>
  245. <p>This proposal does not strictly depend on proposal <a class="reference external" href="http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2003/n1550.htm">n1550</a>, as there
  246. is a direct mapping between new and old categories. This proposal
  247. could be reformulated using this mapping if <a class="reference external" href="http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2003/n1550.htm">n1550</a> was not accepted.</p>
  248. </div>
  249. <div class="section" id="interoperability">
  250. <h2><a class="toc-backref" href="#id19">Interoperability</a></h2>
  251. <p>The question of iterator interoperability is poorly addressed in the
  252. current standard. There are currently two defect reports that are
  253. concerned with interoperability issues.</p>
  254. <p>Issue <a class="reference external" href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#179">179</a> concerns the fact that mutable container iterator types
  255. are only required to be convertible to the corresponding constant
  256. iterator types, but objects of these types are not required to
  257. interoperate in comparison or subtraction expressions. This situation
  258. is tedious in practice and out of line with the way built in types
  259. work. This proposal implements the proposed resolution to issue
  260. <a class="reference external" href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#179">179</a>, as most standard library implementations do nowadays. In other
  261. words, if an iterator type A has an implicit or user defined
  262. conversion to an iterator type B, the iterator types are interoperable
  263. and the usual set of operators are available.</p>
  264. <p>Issue <a class="reference external" href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html#280">280</a> concerns the current lack of interoperability between
  265. reverse iterator types. The proposed new reverse_iterator template
  266. fixes the issues raised in 280. It provides the desired
  267. interoperability without introducing unwanted overloads.</p>
  268. </div>
  269. <div class="section" id="iterator-facade">
  270. <h2><a class="toc-backref" href="#id20">Iterator Facade</a></h2>
  271. <!-- Distributed under the Boost -->
  272. <!-- Software License, Version 1.0. (See accompanying -->
  273. <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
  274. <!-- Version 1.1 of this ReStructuredText document corresponds to
  275. n1530_, the paper accepted by the LWG for TR1. -->
  276. <!-- Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. -->
  277. <p>While the iterator interface is rich, there is a core subset of the
  278. interface that is necessary for all the functionality. We have
  279. identified the following core behaviors for iterators:</p>
  280. <ul class="simple">
  281. <li>dereferencing</li>
  282. <li>incrementing</li>
  283. <li>decrementing</li>
  284. <li>equality comparison</li>
  285. <li>random-access motion</li>
  286. <li>distance measurement</li>
  287. </ul>
  288. <p>In addition to the behaviors listed above, the core interface elements
  289. include the associated types exposed through iterator traits:
  290. <tt class="docutils literal"><span class="pre">value_type</span></tt>, <tt class="docutils literal"><span class="pre">reference</span></tt>, <tt class="docutils literal"><span class="pre">difference_type</span></tt>, and
  291. <tt class="docutils literal"><span class="pre">iterator_category</span></tt>.</p>
  292. <p>Iterator facade uses the Curiously Recurring Template
  293. Pattern (CRTP) <a class="citation-reference" href="#cop95" id="id4">[Cop95]</a> so that the user can specify the behavior
  294. of <tt class="docutils literal"><span class="pre">iterator_facade</span></tt> in a derived class. Former designs used
  295. policy objects to specify the behavior, but that approach was
  296. discarded for several reasons:</p>
  297. <blockquote>
  298. <ol class="arabic simple">
  299. <li>the creation and eventual copying of the policy object may create
  300. overhead that can be avoided with the current approach.</li>
  301. <li>The policy object approach does not allow for custom constructors
  302. on the created iterator types, an essential feature if
  303. <tt class="docutils literal"><span class="pre">iterator_facade</span></tt> should be used in other library
  304. implementations.</li>
  305. <li>Without the use of CRTP, the standard requirement that an
  306. iterator's <tt class="docutils literal"><span class="pre">operator++</span></tt> returns the iterator type itself
  307. would mean that all iterators built with the library would
  308. have to be specializations of <tt class="docutils literal"><span class="pre">iterator_facade&lt;...&gt;</span></tt>, rather
  309. than something more descriptive like
  310. <tt class="docutils literal"><span class="pre">indirect_iterator&lt;T*&gt;</span></tt>. Cumbersome type generator
  311. metafunctions would be needed to build new parameterized
  312. iterators, and a separate <tt class="docutils literal"><span class="pre">iterator_adaptor</span></tt> layer would be
  313. impossible.</li>
  314. </ol>
  315. </blockquote>
  316. <div class="section" id="usage">
  317. <h3><a class="toc-backref" href="#id21">Usage</a></h3>
  318. <p>The user of <tt class="docutils literal"><span class="pre">iterator_facade</span></tt> derives his iterator class from a
  319. specialization of <tt class="docutils literal"><span class="pre">iterator_facade</span></tt> and passes the derived
  320. iterator class as <tt class="docutils literal"><span class="pre">iterator_facade</span></tt>'s first template parameter.
  321. The order of the other template parameters have been carefully
  322. chosen to take advantage of useful defaults. For example, when
  323. defining a constant lvalue iterator, the user can pass a
  324. const-qualified version of the iterator's <tt class="docutils literal"><span class="pre">value_type</span></tt> as
  325. <tt class="docutils literal"><span class="pre">iterator_facade</span></tt>'s <tt class="docutils literal"><span class="pre">Value</span></tt> parameter and omit the
  326. <tt class="docutils literal"><span class="pre">Reference</span></tt> parameter which follows.</p>
  327. <p>The derived iterator class must define member functions implementing
  328. the iterator's core behaviors. The following table describes
  329. expressions which are required to be valid depending on the category
  330. of the derived iterator type. These member functions are described
  331. briefly below and in more detail in the iterator facade
  332. requirements.</p>
  333. <blockquote>
  334. <table border="1" class="docutils">
  335. <colgroup>
  336. <col width="44%" />
  337. <col width="56%" />
  338. </colgroup>
  339. <thead valign="bottom">
  340. <tr><th class="head">Expression</th>
  341. <th class="head">Effects</th>
  342. </tr>
  343. </thead>
  344. <tbody valign="top">
  345. <tr><td><tt class="docutils literal"><span class="pre">i.dereference()</span></tt></td>
  346. <td>Access the value referred to</td>
  347. </tr>
  348. <tr><td><tt class="docutils literal"><span class="pre">i.equal(j)</span></tt></td>
  349. <td>Compare for equality with <tt class="docutils literal"><span class="pre">j</span></tt></td>
  350. </tr>
  351. <tr><td><tt class="docutils literal"><span class="pre">i.increment()</span></tt></td>
  352. <td>Advance by one position</td>
  353. </tr>
  354. <tr><td><tt class="docutils literal"><span class="pre">i.decrement()</span></tt></td>
  355. <td>Retreat by one position</td>
  356. </tr>
  357. <tr><td><tt class="docutils literal"><span class="pre">i.advance(n)</span></tt></td>
  358. <td>Advance by <tt class="docutils literal"><span class="pre">n</span></tt> positions</td>
  359. </tr>
  360. <tr><td><tt class="docutils literal"><span class="pre">i.distance_to(j)</span></tt></td>
  361. <td>Measure the distance to <tt class="docutils literal"><span class="pre">j</span></tt></td>
  362. </tr>
  363. </tbody>
  364. </table>
  365. </blockquote>
  366. <!-- Should we add a comment that a zero overhead implementation of iterator_facade
  367. is possible with proper inlining? -->
  368. <p>In addition to implementing the core interface functions, an iterator
  369. derived from <tt class="docutils literal"><span class="pre">iterator_facade</span></tt> typically defines several
  370. constructors. To model any of the standard iterator concepts, the
  371. iterator must at least have a copy constructor. Also, if the iterator
  372. type <tt class="docutils literal"><span class="pre">X</span></tt> is meant to be automatically interoperate with another
  373. iterator type <tt class="docutils literal"><span class="pre">Y</span></tt> (as with constant and mutable iterators) then
  374. there must be an implicit conversion from <tt class="docutils literal"><span class="pre">X</span></tt> to <tt class="docutils literal"><span class="pre">Y</span></tt> or from <tt class="docutils literal"><span class="pre">Y</span></tt>
  375. to <tt class="docutils literal"><span class="pre">X</span></tt> (but not both), typically implemented as a conversion
  376. constructor. Finally, if the iterator is to model Forward Traversal
  377. Iterator or a more-refined iterator concept, a default constructor is
  378. required.</p>
  379. </div>
  380. <div class="section" id="iterator-core-access">
  381. <h3><a class="toc-backref" href="#id22">Iterator Core Access</a></h3>
  382. <p><tt class="docutils literal"><span class="pre">iterator_facade</span></tt> and the operator implementations need to be able
  383. to access the core member functions in the derived class. Making the
  384. core member functions public would expose an implementation detail to
  385. the user. The design used here ensures that implementation details do
  386. not appear in the public interface of the derived iterator type.</p>
  387. <p>Preventing direct access to the core member functions has two
  388. advantages. First, there is no possibility for the user to accidently
  389. use a member function of the iterator when a member of the value_type
  390. was intended. This has been an issue with smart pointer
  391. implementations in the past. The second and main advantage is that
  392. library implementers can freely exchange a hand-rolled iterator
  393. implementation for one based on <tt class="docutils literal"><span class="pre">iterator_facade</span></tt> without fear of
  394. breaking code that was accessing the public core member functions
  395. directly.</p>
  396. <p>In a naive implementation, keeping the derived class' core member
  397. functions private would require it to grant friendship to
  398. <tt class="docutils literal"><span class="pre">iterator_facade</span></tt> and each of the seven operators. In order to
  399. reduce the burden of limiting access, <tt class="docutils literal"><span class="pre">iterator_core_access</span></tt> is
  400. provided, a class that acts as a gateway to the core member functions
  401. in the derived iterator class. The author of the derived class only
  402. needs to grant friendship to <tt class="docutils literal"><span class="pre">iterator_core_access</span></tt> to make his core
  403. member functions available to the library.</p>
  404. <!-- This is no long uptodate -thw -->
  405. <!-- Yes it is; I made sure of it! -DWA -->
  406. <p><tt class="docutils literal"><span class="pre">iterator_core_access</span></tt> will be typically implemented as an empty
  407. class containing only private static member functions which invoke the
  408. iterator core member functions. There is, however, no need to
  409. standardize the gateway protocol. Note that even if
  410. <tt class="docutils literal"><span class="pre">iterator_core_access</span></tt> used public member functions it would not
  411. open a safety loophole, as every core member function preserves the
  412. invariants of the iterator.</p>
  413. </div>
  414. <div class="section" id="operator">
  415. <h3><a class="toc-backref" href="#id23"><tt class="docutils literal"><span class="pre">operator[]</span></tt></a></h3>
  416. <p>The indexing operator for a generalized iterator presents special
  417. challenges. A random access iterator's <tt class="docutils literal"><span class="pre">operator[]</span></tt> is only
  418. required to return something convertible to its <tt class="docutils literal"><span class="pre">value_type</span></tt>.
  419. Requiring that it return an lvalue would rule out currently-legal
  420. random-access iterators which hold the referenced value in a data
  421. member (e.g. <a class="reference internal" href="#counting"><tt class="docutils literal"><span class="pre">counting_iterator</span></tt></a>), because <tt class="docutils literal"><span class="pre">*(p+n)</span></tt> is a reference
  422. into the temporary iterator <tt class="docutils literal"><span class="pre">p+n</span></tt>, which is destroyed when
  423. <tt class="docutils literal"><span class="pre">operator[]</span></tt> returns.</p>
  424. <p>Writable iterators built with <tt class="docutils literal"><span class="pre">iterator_facade</span></tt> implement the
  425. semantics required by the preferred resolution to <a class="reference external" href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html#299">issue 299</a> and
  426. adopted by proposal <a class="reference external" href="http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2003/n1550.htm">n1550</a>: the result of <tt class="docutils literal"><span class="pre">p[n]</span></tt> is an object
  427. convertible to the iterator's <tt class="docutils literal"><span class="pre">value_type</span></tt>, and <tt class="docutils literal"><span class="pre">p[n]</span> <span class="pre">=</span> <span class="pre">x</span></tt> is
  428. equivalent to <tt class="docutils literal"><span class="pre">*(p</span> <span class="pre">+</span> <span class="pre">n)</span> <span class="pre">=</span> <span class="pre">x</span></tt> (Note: This result object may be
  429. implemented as a proxy containing a copy of <tt class="docutils literal"><span class="pre">p+n</span></tt>). This approach
  430. will work properly for any random-access iterator regardless of the
  431. other details of its implementation. A user who knows more about
  432. the implementation of her iterator is free to implement an
  433. <tt class="docutils literal"><span class="pre">operator[]</span></tt> that returns an lvalue in the derived iterator
  434. class; it will hide the one supplied by <tt class="docutils literal"><span class="pre">iterator_facade</span></tt> from
  435. clients of her iterator.</p>
  436. </div>
  437. <div class="section" id="id6">
  438. <span id="operator-arrow"></span><h3><a class="toc-backref" href="#id24"><tt class="docutils literal"><span class="pre">operator-&gt;</span></tt></a></h3>
  439. <p>The <tt class="docutils literal"><span class="pre">reference</span></tt> type of a readable iterator (and today's input
  440. iterator) need not in fact be a reference, so long as it is
  441. convertible to the iterator's <tt class="docutils literal"><span class="pre">value_type</span></tt>. When the <tt class="docutils literal"><span class="pre">value_type</span></tt>
  442. is a class, however, it must still be possible to access members
  443. through <tt class="docutils literal"><span class="pre">operator-&gt;</span></tt>. Therefore, an iterator whose <tt class="docutils literal"><span class="pre">reference</span></tt>
  444. type is not in fact a reference must return a proxy containing a copy
  445. of the referenced value from its <tt class="docutils literal"><span class="pre">operator-&gt;</span></tt>.</p>
  446. <p>The return types for <tt class="docutils literal"><span class="pre">iterator_facade</span></tt>'s <tt class="docutils literal"><span class="pre">operator-&gt;</span></tt> and
  447. <tt class="docutils literal"><span class="pre">operator[]</span></tt> are not explicitly specified. Instead, those types
  448. are described in terms of a set of requirements, which must be
  449. satisfied by the <tt class="docutils literal"><span class="pre">iterator_facade</span></tt> implementation.</p>
  450. <table class="docutils citation" frame="void" id="cop95" rules="none">
  451. <colgroup><col class="label" /><col /></colgroup>
  452. <tbody valign="top">
  453. <tr><td class="label"><a class="fn-backref" href="#id4">[Cop95]</a></td><td>[Coplien, 1995] Coplien, J., Curiously Recurring Template
  454. Patterns, C++ Report, February 1995, pp. 24-27.</td></tr>
  455. </tbody>
  456. </table>
  457. </div>
  458. </div>
  459. <div class="section" id="iterator-adaptor">
  460. <h2><a class="toc-backref" href="#id25">Iterator Adaptor</a></h2>
  461. <!-- Distributed under the Boost -->
  462. <!-- Software License, Version 1.0. (See accompanying -->
  463. <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
  464. <!-- Version 1.2 of this ReStructuredText document corresponds to
  465. n1530_, the paper accepted by the LWG for TR1. -->
  466. <!-- Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. -->
  467. <p>The <tt class="docutils literal"><span class="pre">iterator_adaptor</span></tt> class template adapts some <tt class="docutils literal"><span class="pre">Base</span></tt><a class="footnote-reference" href="#base" id="id7"><sup>3</sup></a>
  468. type to create a new iterator. Instantiations of <tt class="docutils literal"><span class="pre">iterator_adaptor</span></tt>
  469. are derived from a corresponding instantiation of <tt class="docutils literal"><span class="pre">iterator_facade</span></tt>
  470. and implement the core behaviors in terms of the <tt class="docutils literal"><span class="pre">Base</span></tt> type. In
  471. essence, <tt class="docutils literal"><span class="pre">iterator_adaptor</span></tt> merely forwards all operations to an
  472. instance of the <tt class="docutils literal"><span class="pre">Base</span></tt> type, which it stores as a member.</p>
  473. <table class="docutils footnote" frame="void" id="base" rules="none">
  474. <colgroup><col class="label" /><col /></colgroup>
  475. <tbody valign="top">
  476. <tr><td class="label"><a class="fn-backref" href="#id7">[3]</a></td><td>The term &quot;Base&quot; here does not refer to a base class and is
  477. not meant to imply the use of derivation. We have followed the lead
  478. of the standard library, which provides a base() function to access
  479. the underlying iterator object of a <tt class="docutils literal"><span class="pre">reverse_iterator</span></tt> adaptor.</td></tr>
  480. </tbody>
  481. </table>
  482. <p>The user of <tt class="docutils literal"><span class="pre">iterator_adaptor</span></tt> creates a class derived from an
  483. instantiation of <tt class="docutils literal"><span class="pre">iterator_adaptor</span></tt> and then selectively
  484. redefines some of the core member functions described in the
  485. <tt class="docutils literal"><span class="pre">iterator_facade</span></tt> core requirements table. The <tt class="docutils literal"><span class="pre">Base</span></tt> type need
  486. not meet the full requirements for an iterator; it need only
  487. support the operations used by the core interface functions of
  488. <tt class="docutils literal"><span class="pre">iterator_adaptor</span></tt> that have not been redefined in the user's
  489. derived class.</p>
  490. <p>Several of the template parameters of <tt class="docutils literal"><span class="pre">iterator_adaptor</span></tt> default
  491. to <tt class="docutils literal"><span class="pre">use_default</span></tt>. This allows the
  492. user to make use of a default parameter even when she wants to
  493. specify a parameter later in the parameter list. Also, the
  494. defaults for the corresponding associated types are somewhat
  495. complicated, so metaprogramming is required to compute them, and
  496. <tt class="docutils literal"><span class="pre">use_default</span></tt> can help to simplify the implementation. Finally,
  497. the identity of the <tt class="docutils literal"><span class="pre">use_default</span></tt> type is not left unspecified
  498. because specification helps to highlight that the <tt class="docutils literal"><span class="pre">Reference</span></tt>
  499. template parameter may not always be identical to the iterator's
  500. <tt class="docutils literal"><span class="pre">reference</span></tt> type, and will keep users from making mistakes based on
  501. that assumption.</p>
  502. </div>
  503. <div class="section" id="specialized-adaptors">
  504. <h2><a class="toc-backref" href="#id26">Specialized Adaptors</a></h2>
  505. <p>This proposal also contains several examples of specialized adaptors
  506. which were easily implemented using <tt class="docutils literal"><span class="pre">iterator_adaptor</span></tt>:</p>
  507. <ul class="simple">
  508. <li><tt class="docutils literal"><span class="pre">indirect_iterator</span></tt>, which iterates over iterators, pointers,
  509. or smart pointers and applies an extra level of dereferencing.</li>
  510. <li>A new <tt class="docutils literal"><span class="pre">reverse_iterator</span></tt>, which inverts the direction of a Base
  511. iterator's motion, while allowing adapted constant and mutable
  512. iterators to interact in the expected ways (unlike those in most
  513. implementations of C++98).</li>
  514. <li><tt class="docutils literal"><span class="pre">transform_iterator</span></tt>, which applies a user-defined function object
  515. to the underlying values when dereferenced.</li>
  516. <li><tt class="docutils literal"><span class="pre">filter_iterator</span></tt>, which provides a view of an iterator range in
  517. which some elements of the underlying range are skipped.</li>
  518. </ul>
  519. <ul class="simple" id="counting">
  520. <li><tt class="docutils literal"><span class="pre">counting_iterator</span></tt>, which adapts any incrementable type
  521. (e.g. integers, iterators) so that incrementing/decrementing the
  522. adapted iterator and dereferencing it produces successive values of
  523. the Base type.</li>
  524. <li><tt class="docutils literal"><span class="pre">function_output_iterator</span></tt>, which makes it easier to create custom
  525. output iterators.</li>
  526. </ul>
  527. <p>Based on examples in the Boost library, users have generated many new
  528. adaptors, among them a permutation adaptor which applies some
  529. permutation to a random access iterator, and a strided adaptor, which
  530. adapts a random access iterator by multiplying its unit of motion by a
  531. constant factor. In addition, the Boost Graph Library (BGL) uses
  532. iterator adaptors to adapt other graph libraries, such as LEDA [10]
  533. and Stanford GraphBase [8], to the BGL interface (which requires C++
  534. Standard compliant iterators).</p>
  535. </div>
  536. </div>
  537. <div class="section" id="proposed-text">
  538. <h1><a class="toc-backref" href="#id27">Proposed Text</a></h1>
  539. <div class="section" id="header-iterator-helper-synopsis-lib-iterator-helper-synopsis">
  540. <h2><a class="toc-backref" href="#id28">Header <tt class="docutils literal"><span class="pre">&lt;iterator_helper&gt;</span></tt> synopsis [lib.iterator.helper.synopsis]</a></h2>
  541. <pre class="literal-block">
  542. struct use_default;
  543. struct iterator_core_access { /* implementation detail */ };
  544. template &lt;
  545. class Derived
  546. , class Value
  547. , class CategoryOrTraversal
  548. , class Reference = Value&amp;
  549. , class Difference = ptrdiff_t
  550. &gt;
  551. class iterator_facade;
  552. template &lt;
  553. class Derived
  554. , class Base
  555. , class Value = use_default
  556. , class CategoryOrTraversal = use_default
  557. , class Reference = use_default
  558. , class Difference = use_default
  559. &gt;
  560. class iterator_adaptor;
  561. template &lt;
  562. class Iterator
  563. , class Value = use_default
  564. , class CategoryOrTraversal = use_default
  565. , class Reference = use_default
  566. , class Difference = use_default
  567. &gt;
  568. class indirect_iterator;
  569. template &lt;class Dereferenceable&gt;
  570. struct pointee;
  571. template &lt;class Dereferenceable&gt;
  572. struct indirect_reference;
  573. template &lt;class Iterator&gt;
  574. class reverse_iterator;
  575. template &lt;
  576. class UnaryFunction
  577. , class Iterator
  578. , class Reference = use_default
  579. , class Value = use_default
  580. &gt;
  581. class transform_iterator;
  582. template &lt;class Predicate, class Iterator&gt;
  583. class filter_iterator;
  584. template &lt;
  585. class Incrementable
  586. , class CategoryOrTraversal = use_default
  587. , class Difference = use_default
  588. &gt;
  589. class counting_iterator;
  590. template &lt;class UnaryFunction&gt;
  591. class function_output_iterator;
  592. </pre>
  593. </div>
  594. <div class="section" id="iterator-facade-lib-iterator-facade">
  595. <h2><a class="toc-backref" href="#id29">Iterator facade [lib.iterator.facade]</a></h2>
  596. <!-- Copyright David Abrahams 2006. Distributed under the Boost -->
  597. <!-- Software License, Version 1.0. (See accompanying -->
  598. <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
  599. <p><tt class="docutils literal"><span class="pre">iterator_facade</span></tt> is a base class template that implements the
  600. interface of standard iterators in terms of a few core functions
  601. and associated types, to be supplied by a derived iterator class.</p>
  602. <div class="section" id="class-template-iterator-facade">
  603. <h3><a class="toc-backref" href="#id30">Class template <tt class="docutils literal"><span class="pre">iterator_facade</span></tt></a></h3>
  604. <!-- Distributed under the Boost -->
  605. <!-- Software License, Version 1.0. (See accompanying -->
  606. <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
  607. <!-- Version 1.3 of this ReStructuredText document corresponds to
  608. n1530_, the paper accepted by the LWG for TR1. -->
  609. <!-- Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. -->
  610. <pre class="literal-block">
  611. template &lt;
  612. class Derived
  613. , class Value
  614. , class CategoryOrTraversal
  615. , class Reference = Value&amp;
  616. , class Difference = ptrdiff_t
  617. &gt;
  618. class iterator_facade {
  619. public:
  620. typedef remove_const&lt;Value&gt;::type value_type;
  621. typedef Reference reference;
  622. typedef Value* pointer;
  623. typedef Difference difference_type;
  624. typedef /* see <a class="reference internal" href="#iterator-category">below</a> */ iterator_category;
  625. reference operator*() const;
  626. /* see <a class="reference internal" href="#operator-arrow">below</a> */ operator-&gt;() const;
  627. /* see <a class="reference internal" href="#brackets">below</a> */ operator[](difference_type n) const;
  628. Derived&amp; operator++();
  629. Derived operator++(int);
  630. Derived&amp; operator--();
  631. Derived operator--(int);
  632. Derived&amp; operator+=(difference_type n);
  633. Derived&amp; operator-=(difference_type n);
  634. Derived operator-(difference_type n) const;
  635. protected:
  636. typedef iterator_facade iterator_facade_;
  637. };
  638. // Comparison operators
  639. template &lt;class Dr1, class V1, class TC1, class R1, class D1,
  640. class Dr2, class V2, class TC2, class R2, class D2&gt;
  641. typename enable_if_interoperable&lt;Dr1,Dr2,bool&gt;::type // exposition
  642. operator ==(iterator_facade&lt;Dr1,V1,TC1,R1,D1&gt; const&amp; lhs,
  643. iterator_facade&lt;Dr2,V2,TC2,R2,D2&gt; const&amp; rhs);
  644. template &lt;class Dr1, class V1, class TC1, class R1, class D1,
  645. class Dr2, class V2, class TC2, class R2, class D2&gt;
  646. typename enable_if_interoperable&lt;Dr1,Dr2,bool&gt;::type
  647. operator !=(iterator_facade&lt;Dr1,V1,TC1,R1,D1&gt; const&amp; lhs,
  648. iterator_facade&lt;Dr2,V2,TC2,R2,D2&gt; const&amp; rhs);
  649. template &lt;class Dr1, class V1, class TC1, class R1, class D1,
  650. class Dr2, class V2, class TC2, class R2, class D2&gt;
  651. typename enable_if_interoperable&lt;Dr1,Dr2,bool&gt;::type
  652. operator &lt;(iterator_facade&lt;Dr1,V1,TC1,R1,D1&gt; const&amp; lhs,
  653. iterator_facade&lt;Dr2,V2,TC2,R2,D2&gt; const&amp; rhs);
  654. template &lt;class Dr1, class V1, class TC1, class R1, class D1,
  655. class Dr2, class V2, class TC2, class R2, class D2&gt;
  656. typename enable_if_interoperable&lt;Dr1,Dr2,bool&gt;::type
  657. operator &lt;=(iterator_facade&lt;Dr1,V1,TC1,R1,D1&gt; const&amp; lhs,
  658. iterator_facade&lt;Dr2,V2,TC2,R2,D2&gt; const&amp; rhs);
  659. template &lt;class Dr1, class V1, class TC1, class R1, class D1,
  660. class Dr2, class V2, class TC2, class R2, class D2&gt;
  661. typename enable_if_interoperable&lt;Dr1,Dr2,bool&gt;::type
  662. operator &gt;(iterator_facade&lt;Dr1,V1,TC1,R1,D1&gt; const&amp; lhs,
  663. iterator_facade&lt;Dr2,V2,TC2,R2,D2&gt; const&amp; rhs);
  664. template &lt;class Dr1, class V1, class TC1, class R1, class D1,
  665. class Dr2, class V2, class TC2, class R2, class D2&gt;
  666. typename enable_if_interoperable&lt;Dr1,Dr2,bool&gt;::type
  667. operator &gt;=(iterator_facade&lt;Dr1,V1,TC1,R1,D1&gt; const&amp; lhs,
  668. iterator_facade&lt;Dr2,V2,TC2,R2,D2&gt; const&amp; rhs);
  669. // Iterator difference
  670. template &lt;class Dr1, class V1, class TC1, class R1, class D1,
  671. class Dr2, class V2, class TC2, class R2, class D2&gt;
  672. /* see <a class="reference internal" href="#minus">below</a> */
  673. operator-(iterator_facade&lt;Dr1,V1,TC1,R1,D1&gt; const&amp; lhs,
  674. iterator_facade&lt;Dr2,V2,TC2,R2,D2&gt; const&amp; rhs);
  675. // Iterator addition
  676. template &lt;class Dr, class V, class TC, class R, class D&gt;
  677. Derived operator+ (iterator_facade&lt;Dr,V,TC,R,D&gt; const&amp;,
  678. typename Derived::difference_type n);
  679. template &lt;class Dr, class V, class TC, class R, class D&gt;
  680. Derived operator+ (typename Derived::difference_type n,
  681. iterator_facade&lt;Dr,V,TC,R,D&gt; const&amp;);
  682. </pre>
  683. <p id="iterator-category">The <tt class="docutils literal"><span class="pre">iterator_category</span></tt> member of <tt class="docutils literal"><span class="pre">iterator_facade</span></tt> is</p>
  684. <pre class="literal-block">
  685. <em>iterator-category</em>(CategoryOrTraversal, value_type, reference)
  686. </pre>
  687. <p>where <em>iterator-category</em> is defined as follows:</p>
  688. <pre class="literal-block" id="id12">
  689. <em>iterator-category</em>(C,R,V) :=
  690. if (C is convertible to std::input_iterator_tag
  691. || C is convertible to std::output_iterator_tag
  692. )
  693. return C
  694. else if (C is not convertible to incrementable_traversal_tag)
  695. <em>the program is ill-formed</em>
  696. else return a type X satisfying the following two constraints:
  697. 1. X is convertible to X1, and not to any more-derived
  698. type, where X1 is defined by:
  699. if (R is a reference type
  700. &amp;&amp; C is convertible to forward_traversal_tag)
  701. {
  702. if (C is convertible to random_access_traversal_tag)
  703. X1 = random_access_iterator_tag
  704. else if (C is convertible to bidirectional_traversal_tag)
  705. X1 = bidirectional_iterator_tag
  706. else
  707. X1 = forward_iterator_tag
  708. }
  709. else
  710. {
  711. if (C is convertible to single_pass_traversal_tag
  712. &amp;&amp; R is convertible to V)
  713. X1 = input_iterator_tag
  714. else
  715. X1 = C
  716. }
  717. 2. <a class="reference external" href="new-iter-concepts.html#category-to-traversal"><em>category-to-traversal</em></a>(X) is convertible to the most
  718. derived traversal tag type to which X is also
  719. convertible, and not to any more-derived traversal tag
  720. type.
  721. </pre>
  722. <p>[Note: the intention is to allow <tt class="docutils literal"><span class="pre">iterator_category</span></tt> to be one of
  723. the five original category tags when convertibility to one of the
  724. traversal tags would add no information]</p>
  725. <!-- Copyright David Abrahams 2004. Use, modification and distribution is -->
  726. <!-- subject to the Boost Software License, Version 1.0. (See accompanying -->
  727. <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
  728. <p>The <tt class="docutils literal"><span class="pre">enable_if_interoperable</span></tt> template used above is for exposition
  729. purposes. The member operators should only be in an overload set
  730. provided the derived types <tt class="docutils literal"><span class="pre">Dr1</span></tt> and <tt class="docutils literal"><span class="pre">Dr2</span></tt> are interoperable,
  731. meaning that at least one of the types is convertible to the other. The
  732. <tt class="docutils literal"><span class="pre">enable_if_interoperable</span></tt> approach uses SFINAE to take the operators
  733. out of the overload set when the types are not interoperable.
  734. The operators should behave <em>as-if</em> <tt class="docutils literal"><span class="pre">enable_if_interoperable</span></tt>
  735. were defined to be:</p>
  736. <pre class="literal-block">
  737. template &lt;bool, typename&gt; enable_if_interoperable_impl
  738. {};
  739. template &lt;typename T&gt; enable_if_interoperable_impl&lt;true,T&gt;
  740. { typedef T type; };
  741. template&lt;typename Dr1, typename Dr2, typename T&gt;
  742. struct enable_if_interoperable
  743. : enable_if_interoperable_impl&lt;
  744. is_convertible&lt;Dr1,Dr2&gt;::value || is_convertible&lt;Dr2,Dr1&gt;::value
  745. , T
  746. &gt;
  747. {};
  748. </pre>
  749. </div>
  750. <div class="section" id="iterator-facade-requirements">
  751. <h3><a class="toc-backref" href="#id31"><tt class="docutils literal"><span class="pre">iterator_facade</span></tt> Requirements</a></h3>
  752. <p>The following table describes the typical valid expressions on
  753. <tt class="docutils literal"><span class="pre">iterator_facade</span></tt>'s <tt class="docutils literal"><span class="pre">Derived</span></tt> parameter, depending on the
  754. iterator concept(s) it will model. The operations in the first
  755. column must be made accessible to member functions of class
  756. <tt class="docutils literal"><span class="pre">iterator_core_access</span></tt>. In addition,
  757. <tt class="docutils literal"><span class="pre">static_cast&lt;Derived*&gt;(iterator_facade*)</span></tt> shall be well-formed.</p>
  758. <p>In the table below, <tt class="docutils literal"><span class="pre">F</span></tt> is <tt class="docutils literal"><span class="pre">iterator_facade&lt;X,V,C,R,D&gt;</span></tt>, <tt class="docutils literal"><span class="pre">a</span></tt> is an
  759. object of type <tt class="docutils literal"><span class="pre">X</span></tt>, <tt class="docutils literal"><span class="pre">b</span></tt> and <tt class="docutils literal"><span class="pre">c</span></tt> are objects of type <tt class="docutils literal"><span class="pre">const</span> <span class="pre">X</span></tt>,
  760. <tt class="docutils literal"><span class="pre">n</span></tt> is an object of <tt class="docutils literal"><span class="pre">F::difference_type</span></tt>, <tt class="docutils literal"><span class="pre">y</span></tt> is a constant
  761. object of a single pass iterator type interoperable with <tt class="docutils literal"><span class="pre">X</span></tt>, and <tt class="docutils literal"><span class="pre">z</span></tt>
  762. is a constant object of a random access traversal iterator type
  763. interoperable with <tt class="docutils literal"><span class="pre">X</span></tt>.</p>
  764. <div class="topic" id="core-operations">
  765. <p class="topic-title first"><tt class="docutils literal"><span class="pre">iterator_facade</span></tt> Core Operations</p>
  766. <table border="1" class="docutils">
  767. <colgroup>
  768. <col width="21%" />
  769. <col width="23%" />
  770. <col width="27%" />
  771. <col width="29%" />
  772. </colgroup>
  773. <thead valign="bottom">
  774. <tr><th class="head">Expression</th>
  775. <th class="head">Return Type</th>
  776. <th class="head">Assertion/Note</th>
  777. <th class="head">Used to implement Iterator
  778. Concept(s)</th>
  779. </tr>
  780. </thead>
  781. <tbody valign="top">
  782. <tr><td><tt class="docutils literal"><span class="pre">c.dereference()</span></tt></td>
  783. <td><tt class="docutils literal"><span class="pre">F::reference</span></tt></td>
  784. <td>&nbsp;</td>
  785. <td>Readable Iterator, Writable
  786. Iterator</td>
  787. </tr>
  788. <tr><td><tt class="docutils literal"><span class="pre">c.equal(y)</span></tt></td>
  789. <td>convertible to bool</td>
  790. <td>true iff <tt class="docutils literal"><span class="pre">c</span></tt> and <tt class="docutils literal"><span class="pre">y</span></tt>
  791. refer to the same
  792. position.</td>
  793. <td>Single Pass Iterator</td>
  794. </tr>
  795. <tr><td><tt class="docutils literal"><span class="pre">a.increment()</span></tt></td>
  796. <td>unused</td>
  797. <td>&nbsp;</td>
  798. <td>Incrementable Iterator</td>
  799. </tr>
  800. <tr><td><tt class="docutils literal"><span class="pre">a.decrement()</span></tt></td>
  801. <td>unused</td>
  802. <td>&nbsp;</td>
  803. <td>Bidirectional Traversal
  804. Iterator</td>
  805. </tr>
  806. <tr><td><tt class="docutils literal"><span class="pre">a.advance(n)</span></tt></td>
  807. <td>unused</td>
  808. <td>&nbsp;</td>
  809. <td>Random Access Traversal
  810. Iterator</td>
  811. </tr>
  812. <tr><td><tt class="docutils literal"><span class="pre">c.distance_to(z)</span></tt></td>
  813. <td>convertible to
  814. <tt class="docutils literal"><span class="pre">F::difference_type</span></tt></td>
  815. <td>equivalent to
  816. <tt class="docutils literal"><span class="pre">distance(c,</span> <span class="pre">X(z))</span></tt>.</td>
  817. <td>Random Access Traversal
  818. Iterator</td>
  819. </tr>
  820. </tbody>
  821. </table>
  822. </div>
  823. </div>
  824. <div class="section" id="iterator-facade-operations">
  825. <h3><a class="toc-backref" href="#id32"><tt class="docutils literal"><span class="pre">iterator_facade</span></tt> operations</a></h3>
  826. <p>The operations in this section are described in terms of operations on
  827. the core interface of <tt class="docutils literal"><span class="pre">Derived</span></tt> which may be inaccessible
  828. (i.e. private). The implementation should access these operations
  829. through member functions of class <tt class="docutils literal"><span class="pre">iterator_core_access</span></tt>.</p>
  830. <p><tt class="docutils literal"><span class="pre">reference</span> <span class="pre">operator*()</span> <span class="pre">const;</span></tt></p>
  831. <table class="docutils field-list" frame="void" rules="none">
  832. <col class="field-name" />
  833. <col class="field-body" />
  834. <tbody valign="top">
  835. <tr class="field"><th class="field-name">Returns:</th><td class="field-body"><tt class="docutils literal"><span class="pre">static_cast&lt;Derived</span> <span class="pre">const*&gt;(this)-&gt;dereference()</span></tt></td>
  836. </tr>
  837. </tbody>
  838. </table>
  839. <p><tt class="docutils literal"><span class="pre">operator-&gt;()</span> <span class="pre">const;</span></tt> (see <a class="reference internal" href="#operator-arrow">below</a>)</p>
  840. <table class="docutils field-list" frame="void" rules="none">
  841. <col class="field-name" />
  842. <col class="field-body" />
  843. <tbody valign="top">
  844. <tr class="field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">If <tt class="docutils literal"><span class="pre">reference</span></tt> is a reference type, an object
  845. of type <tt class="docutils literal"><span class="pre">pointer</span></tt> equal to:</p>
  846. <pre class="literal-block">
  847. &amp;static_cast&lt;Derived const*&gt;(this)-&gt;dereference()
  848. </pre>
  849. <p class="last">Otherwise returns an object of unspecified type such that,
  850. <tt class="docutils literal"><span class="pre">(*static_cast&lt;Derived</span> <span class="pre">const*&gt;(this))-&gt;m</span></tt> is equivalent to <tt class="docutils literal"><span class="pre">(w</span> <span class="pre">=</span> <span class="pre">**static_cast&lt;Derived</span> <span class="pre">const*&gt;(this),</span>
  851. <span class="pre">w.m)</span></tt> for some temporary object <tt class="docutils literal"><span class="pre">w</span></tt> of type <tt class="docutils literal"><span class="pre">value_type</span></tt>.</p>
  852. </td>
  853. </tr>
  854. </tbody>
  855. </table>
  856. <p id="brackets"><em>unspecified</em> <tt class="docutils literal"><span class="pre">operator[](difference_type</span> <span class="pre">n)</span> <span class="pre">const;</span></tt></p>
  857. <table class="docutils field-list" frame="void" rules="none">
  858. <col class="field-name" />
  859. <col class="field-body" />
  860. <tbody valign="top">
  861. <tr class="field"><th class="field-name">Returns:</th><td class="field-body">an object convertible to <tt class="docutils literal"><span class="pre">value_type</span></tt>. For constant
  862. objects <tt class="docutils literal"><span class="pre">v</span></tt> of type <tt class="docutils literal"><span class="pre">value_type</span></tt>, and <tt class="docutils literal"><span class="pre">n</span></tt> of type
  863. <tt class="docutils literal"><span class="pre">difference_type</span></tt>, <tt class="docutils literal"><span class="pre">(*this)[n]</span> <span class="pre">=</span> <span class="pre">v</span></tt> is equivalent to
  864. <tt class="docutils literal"><span class="pre">*(*this</span> <span class="pre">+</span> <span class="pre">n)</span> <span class="pre">=</span> <span class="pre">v</span></tt>, and <tt class="docutils literal"><span class="pre">static_cast&lt;value_type</span>
  865. <span class="pre">const&amp;&gt;((*this)[n])</span></tt> is equivalent to
  866. <tt class="docutils literal"><span class="pre">static_cast&lt;value_type</span> <span class="pre">const&amp;&gt;(*(*this</span> <span class="pre">+</span> <span class="pre">n))</span></tt></td>
  867. </tr>
  868. </tbody>
  869. </table>
  870. <p><tt class="docutils literal"><span class="pre">Derived&amp;</span> <span class="pre">operator++();</span></tt></p>
  871. <table class="docutils field-list" frame="void" rules="none">
  872. <col class="field-name" />
  873. <col class="field-body" />
  874. <tbody valign="top">
  875. <tr class="field"><th class="field-name">Effects:</th><td class="field-body"><pre class="first last literal-block">
  876. static_cast&lt;Derived*&gt;(this)-&gt;increment();
  877. return *static_cast&lt;Derived*&gt;(this);
  878. </pre>
  879. </td>
  880. </tr>
  881. </tbody>
  882. </table>
  883. <p><tt class="docutils literal"><span class="pre">Derived</span> <span class="pre">operator++(int);</span></tt></p>
  884. <table class="docutils field-list" frame="void" rules="none">
  885. <col class="field-name" />
  886. <col class="field-body" />
  887. <tbody valign="top">
  888. <tr class="field"><th class="field-name">Effects:</th><td class="field-body"><pre class="first last literal-block">
  889. Derived tmp(static_cast&lt;Derived const*&gt;(this));
  890. ++*this;
  891. return tmp;
  892. </pre>
  893. </td>
  894. </tr>
  895. </tbody>
  896. </table>
  897. <p><tt class="docutils literal"><span class="pre">Derived&amp;</span> <span class="pre">operator--();</span></tt></p>
  898. <table class="docutils field-list" frame="void" rules="none">
  899. <col class="field-name" />
  900. <col class="field-body" />
  901. <tbody valign="top">
  902. <tr class="field"><th class="field-name">Effects:</th><td class="field-body"><pre class="first last literal-block">
  903. static_cast&lt;Derived*&gt;(this)-&gt;decrement();
  904. return *static_cast&lt;Derived*&gt;(this);
  905. </pre>
  906. </td>
  907. </tr>
  908. </tbody>
  909. </table>
  910. <p><tt class="docutils literal"><span class="pre">Derived</span> <span class="pre">operator--(int);</span></tt></p>
  911. <table class="docutils field-list" frame="void" rules="none">
  912. <col class="field-name" />
  913. <col class="field-body" />
  914. <tbody valign="top">
  915. <tr class="field"><th class="field-name">Effects:</th><td class="field-body"><pre class="first last literal-block">
  916. Derived tmp(static_cast&lt;Derived const*&gt;(this));
  917. --*this;
  918. return tmp;
  919. </pre>
  920. </td>
  921. </tr>
  922. </tbody>
  923. </table>
  924. <p><tt class="docutils literal"><span class="pre">Derived&amp;</span> <span class="pre">operator+=(difference_type</span> <span class="pre">n);</span></tt></p>
  925. <table class="docutils field-list" frame="void" rules="none">
  926. <col class="field-name" />
  927. <col class="field-body" />
  928. <tbody valign="top">
  929. <tr class="field"><th class="field-name">Effects:</th><td class="field-body"><pre class="first last literal-block">
  930. static_cast&lt;Derived*&gt;(this)-&gt;advance(n);
  931. return *static_cast&lt;Derived*&gt;(this);
  932. </pre>
  933. </td>
  934. </tr>
  935. </tbody>
  936. </table>
  937. <p><tt class="docutils literal"><span class="pre">Derived&amp;</span> <span class="pre">operator-=(difference_type</span> <span class="pre">n);</span></tt></p>
  938. <table class="docutils field-list" frame="void" rules="none">
  939. <col class="field-name" />
  940. <col class="field-body" />
  941. <tbody valign="top">
  942. <tr class="field"><th class="field-name">Effects:</th><td class="field-body"><pre class="first last literal-block">
  943. static_cast&lt;Derived*&gt;(this)-&gt;advance(-n);
  944. return *static_cast&lt;Derived*&gt;(this);
  945. </pre>
  946. </td>
  947. </tr>
  948. </tbody>
  949. </table>
  950. <p><tt class="docutils literal"><span class="pre">Derived</span> <span class="pre">operator-(difference_type</span> <span class="pre">n)</span> <span class="pre">const;</span></tt></p>
  951. <table class="docutils field-list" frame="void" rules="none">
  952. <col class="field-name" />
  953. <col class="field-body" />
  954. <tbody valign="top">
  955. <tr class="field"><th class="field-name">Effects:</th><td class="field-body"><pre class="first last literal-block">
  956. Derived tmp(static_cast&lt;Derived const*&gt;(this));
  957. return tmp -= n;
  958. </pre>
  959. </td>
  960. </tr>
  961. </tbody>
  962. </table>
  963. <pre class="literal-block">
  964. template &lt;class Dr, class V, class TC, class R, class D&gt;
  965. Derived operator+ (iterator_facade&lt;Dr,V,TC,R,D&gt; const&amp;,
  966. typename Derived::difference_type n);
  967. template &lt;class Dr, class V, class TC, class R, class D&gt;
  968. Derived operator+ (typename Derived::difference_type n,
  969. iterator_facade&lt;Dr,V,TC,R,D&gt; const&amp;);
  970. </pre>
  971. <table class="docutils field-list" frame="void" rules="none">
  972. <col class="field-name" />
  973. <col class="field-body" />
  974. <tbody valign="top">
  975. <tr class="field"><th class="field-name">Effects:</th><td class="field-body"><pre class="first last literal-block">
  976. Derived tmp(static_cast&lt;Derived const*&gt;(this));
  977. return tmp += n;
  978. </pre>
  979. </td>
  980. </tr>
  981. </tbody>
  982. </table>
  983. <pre class="literal-block">
  984. template &lt;class Dr1, class V1, class TC1, class R1, class D1,
  985. class Dr2, class V2, class TC2, class R2, class D2&gt;
  986. typename enable_if_interoperable&lt;Dr1,Dr2,bool&gt;::type
  987. operator ==(iterator_facade&lt;Dr1,V1,TC1,R1,D1&gt; const&amp; lhs,
  988. iterator_facade&lt;Dr2,V2,TC2,R2,D2&gt; const&amp; rhs);
  989. </pre>
  990. <table class="docutils field-list" frame="void" rules="none">
  991. <col class="field-name" />
  992. <col class="field-body" />
  993. <tbody valign="top">
  994. <tr class="field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">if <tt class="docutils literal"><span class="pre">is_convertible&lt;Dr2,Dr1&gt;::value</span></tt></p>
  995. <dl class="last docutils">
  996. <dt>then</dt>
  997. <dd><p class="first last"><tt class="docutils literal"><span class="pre">((Dr1</span> <span class="pre">const&amp;)lhs).equal((Dr2</span> <span class="pre">const&amp;)rhs)</span></tt>.</p>
  998. </dd>
  999. <dt>Otherwise,</dt>
  1000. <dd><p class="first last"><tt class="docutils literal"><span class="pre">((Dr2</span> <span class="pre">const&amp;)rhs).equal((Dr1</span> <span class="pre">const&amp;)lhs)</span></tt>.</p>
  1001. </dd>
  1002. </dl>
  1003. </td>
  1004. </tr>
  1005. </tbody>
  1006. </table>
  1007. <pre class="literal-block">
  1008. template &lt;class Dr1, class V1, class TC1, class R1, class D1,
  1009. class Dr2, class V2, class TC2, class R2, class D2&gt;
  1010. typename enable_if_interoperable&lt;Dr1,Dr2,bool&gt;::type
  1011. operator !=(iterator_facade&lt;Dr1,V1,TC1,R1,D1&gt; const&amp; lhs,
  1012. iterator_facade&lt;Dr2,V2,TC2,R2,D2&gt; const&amp; rhs);
  1013. </pre>
  1014. <table class="docutils field-list" frame="void" rules="none">
  1015. <col class="field-name" />
  1016. <col class="field-body" />
  1017. <tbody valign="top">
  1018. <tr class="field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">if <tt class="docutils literal"><span class="pre">is_convertible&lt;Dr2,Dr1&gt;::value</span></tt></p>
  1019. <dl class="last docutils">
  1020. <dt>then</dt>
  1021. <dd><p class="first last"><tt class="docutils literal"><span class="pre">!((Dr1</span> <span class="pre">const&amp;)lhs).equal((Dr2</span> <span class="pre">const&amp;)rhs)</span></tt>.</p>
  1022. </dd>
  1023. <dt>Otherwise,</dt>
  1024. <dd><p class="first last"><tt class="docutils literal"><span class="pre">!((Dr2</span> <span class="pre">const&amp;)rhs).equal((Dr1</span> <span class="pre">const&amp;)lhs)</span></tt>.</p>
  1025. </dd>
  1026. </dl>
  1027. </td>
  1028. </tr>
  1029. </tbody>
  1030. </table>
  1031. <pre class="literal-block">
  1032. template &lt;class Dr1, class V1, class TC1, class R1, class D1,
  1033. class Dr2, class V2, class TC2, class R2, class D2&gt;
  1034. typename enable_if_interoperable&lt;Dr1,Dr2,bool&gt;::type
  1035. operator &lt;(iterator_facade&lt;Dr1,V1,TC1,R1,D1&gt; const&amp; lhs,
  1036. iterator_facade&lt;Dr2,V2,TC2,R2,D2&gt; const&amp; rhs);
  1037. </pre>
  1038. <table class="docutils field-list" frame="void" rules="none">
  1039. <col class="field-name" />
  1040. <col class="field-body" />
  1041. <tbody valign="top">
  1042. <tr class="field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">if <tt class="docutils literal"><span class="pre">is_convertible&lt;Dr2,Dr1&gt;::value</span></tt></p>
  1043. <dl class="last docutils">
  1044. <dt>then</dt>
  1045. <dd><p class="first last"><tt class="docutils literal"><span class="pre">((Dr1</span> <span class="pre">const&amp;)lhs).distance_to((Dr2</span> <span class="pre">const&amp;)rhs)</span> <span class="pre">&lt;</span> <span class="pre">0</span></tt>.</p>
  1046. </dd>
  1047. <dt>Otherwise,</dt>
  1048. <dd><p class="first last"><tt class="docutils literal"><span class="pre">((Dr2</span> <span class="pre">const&amp;)rhs).distance_to((Dr1</span> <span class="pre">const&amp;)lhs)</span> <span class="pre">&gt;</span> <span class="pre">0</span></tt>.</p>
  1049. </dd>
  1050. </dl>
  1051. </td>
  1052. </tr>
  1053. </tbody>
  1054. </table>
  1055. <pre class="literal-block">
  1056. template &lt;class Dr1, class V1, class TC1, class R1, class D1,
  1057. class Dr2, class V2, class TC2, class R2, class D2&gt;
  1058. typename enable_if_interoperable&lt;Dr1,Dr2,bool&gt;::type
  1059. operator &lt;=(iterator_facade&lt;Dr1,V1,TC1,R1,D1&gt; const&amp; lhs,
  1060. iterator_facade&lt;Dr2,V2,TC2,R2,D2&gt; const&amp; rhs);
  1061. </pre>
  1062. <table class="docutils field-list" frame="void" rules="none">
  1063. <col class="field-name" />
  1064. <col class="field-body" />
  1065. <tbody valign="top">
  1066. <tr class="field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">if <tt class="docutils literal"><span class="pre">is_convertible&lt;Dr2,Dr1&gt;::value</span></tt></p>
  1067. <dl class="last docutils">
  1068. <dt>then</dt>
  1069. <dd><p class="first last"><tt class="docutils literal"><span class="pre">((Dr1</span> <span class="pre">const&amp;)lhs).distance_to((Dr2</span> <span class="pre">const&amp;)rhs)</span> <span class="pre">&lt;=</span> <span class="pre">0</span></tt>.</p>
  1070. </dd>
  1071. <dt>Otherwise,</dt>
  1072. <dd><p class="first last"><tt class="docutils literal"><span class="pre">((Dr2</span> <span class="pre">const&amp;)rhs).distance_to((Dr1</span> <span class="pre">const&amp;)lhs)</span> <span class="pre">&gt;=</span> <span class="pre">0</span></tt>.</p>
  1073. </dd>
  1074. </dl>
  1075. </td>
  1076. </tr>
  1077. </tbody>
  1078. </table>
  1079. <pre class="literal-block">
  1080. template &lt;class Dr1, class V1, class TC1, class R1, class D1,
  1081. class Dr2, class V2, class TC2, class R2, class D2&gt;
  1082. typename enable_if_interoperable&lt;Dr1,Dr2,bool&gt;::type
  1083. operator &gt;(iterator_facade&lt;Dr1,V1,TC1,R1,D1&gt; const&amp; lhs,
  1084. iterator_facade&lt;Dr2,V2,TC2,R2,D2&gt; const&amp; rhs);
  1085. </pre>
  1086. <table class="docutils field-list" frame="void" rules="none">
  1087. <col class="field-name" />
  1088. <col class="field-body" />
  1089. <tbody valign="top">
  1090. <tr class="field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">if <tt class="docutils literal"><span class="pre">is_convertible&lt;Dr2,Dr1&gt;::value</span></tt></p>
  1091. <dl class="last docutils">
  1092. <dt>then</dt>
  1093. <dd><p class="first last"><tt class="docutils literal"><span class="pre">((Dr1</span> <span class="pre">const&amp;)lhs).distance_to((Dr2</span> <span class="pre">const&amp;)rhs)</span> <span class="pre">&gt;</span> <span class="pre">0</span></tt>.</p>
  1094. </dd>
  1095. <dt>Otherwise,</dt>
  1096. <dd><p class="first last"><tt class="docutils literal"><span class="pre">((Dr2</span> <span class="pre">const&amp;)rhs).distance_to((Dr1</span> <span class="pre">const&amp;)lhs)</span> <span class="pre">&lt;</span> <span class="pre">0</span></tt>.</p>
  1097. </dd>
  1098. </dl>
  1099. </td>
  1100. </tr>
  1101. </tbody>
  1102. </table>
  1103. <pre class="literal-block">
  1104. template &lt;class Dr1, class V1, class TC1, class R1, class D1,
  1105. class Dr2, class V2, class TC2, class R2, class D2&gt;
  1106. typename enable_if_interoperable&lt;Dr1,Dr2,bool&gt;::type
  1107. operator &gt;=(iterator_facade&lt;Dr1,V1,TC1,R1,D1&gt; const&amp; lhs,
  1108. iterator_facade&lt;Dr2,V2,TC2,R2,D2&gt; const&amp; rhs);
  1109. </pre>
  1110. <table class="docutils field-list" frame="void" rules="none">
  1111. <col class="field-name" />
  1112. <col class="field-body" />
  1113. <tbody valign="top">
  1114. <tr class="field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">if <tt class="docutils literal"><span class="pre">is_convertible&lt;Dr2,Dr1&gt;::value</span></tt></p>
  1115. <dl class="last docutils">
  1116. <dt>then</dt>
  1117. <dd><p class="first last"><tt class="docutils literal"><span class="pre">((Dr1</span> <span class="pre">const&amp;)lhs).distance_to((Dr2</span> <span class="pre">const&amp;)rhs)</span> <span class="pre">&gt;=</span> <span class="pre">0</span></tt>.</p>
  1118. </dd>
  1119. <dt>Otherwise,</dt>
  1120. <dd><p class="first last"><tt class="docutils literal"><span class="pre">((Dr2</span> <span class="pre">const&amp;)rhs).distance_to((Dr1</span> <span class="pre">const&amp;)lhs)</span> <span class="pre">&lt;=</span> <span class="pre">0</span></tt>.</p>
  1121. </dd>
  1122. </dl>
  1123. </td>
  1124. </tr>
  1125. </tbody>
  1126. </table>
  1127. <pre class="literal-block" id="minus">
  1128. template &lt;class Dr1, class V1, class TC1, class R1, class D1,
  1129. class Dr2, class V2, class TC2, class R2, class D2&gt;
  1130. typename enable_if_interoperable&lt;Dr1,Dr2,difference&gt;::type
  1131. operator -(iterator_facade&lt;Dr1,V1,TC1,R1,D1&gt; const&amp; lhs,
  1132. iterator_facade&lt;Dr2,V2,TC2,R2,D2&gt; const&amp; rhs);
  1133. </pre>
  1134. <table class="docutils field-list" frame="void" rules="none">
  1135. <col class="field-name" />
  1136. <col class="field-body" />
  1137. <tbody valign="top">
  1138. <tr class="field"><th class="field-name">Return Type:</th><td class="field-body"><p class="first">if <tt class="docutils literal"><span class="pre">is_convertible&lt;Dr2,Dr1&gt;::value</span></tt></p>
  1139. <blockquote>
  1140. <dl class="docutils">
  1141. <dt>then</dt>
  1142. <dd><p class="first last"><tt class="docutils literal"><span class="pre">difference</span></tt> shall be
  1143. <tt class="docutils literal"><span class="pre">iterator_traits&lt;Dr1&gt;::difference_type</span></tt>.</p>
  1144. </dd>
  1145. <dt>Otherwise</dt>
  1146. <dd><p class="first last"><tt class="docutils literal"><span class="pre">difference</span></tt> shall be <tt class="docutils literal"><span class="pre">iterator_traits&lt;Dr2&gt;::difference_type</span></tt></p>
  1147. </dd>
  1148. </dl>
  1149. </blockquote>
  1150. </td>
  1151. </tr>
  1152. <tr class="field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">if <tt class="docutils literal"><span class="pre">is_convertible&lt;Dr2,Dr1&gt;::value</span></tt></p>
  1153. <dl class="last docutils">
  1154. <dt>then</dt>
  1155. <dd><p class="first last"><tt class="docutils literal"><span class="pre">-((Dr1</span> <span class="pre">const&amp;)lhs).distance_to((Dr2</span> <span class="pre">const&amp;)rhs)</span></tt>.</p>
  1156. </dd>
  1157. <dt>Otherwise,</dt>
  1158. <dd><p class="first last"><tt class="docutils literal"><span class="pre">((Dr2</span> <span class="pre">const&amp;)rhs).distance_to((Dr1</span> <span class="pre">const&amp;)lhs)</span></tt>.</p>
  1159. </dd>
  1160. </dl>
  1161. </td>
  1162. </tr>
  1163. </tbody>
  1164. </table>
  1165. </div>
  1166. </div>
  1167. <div class="section" id="iterator-adaptor-lib-iterator-adaptor">
  1168. <h2><a class="toc-backref" href="#id33">Iterator adaptor [lib.iterator.adaptor]</a></h2>
  1169. <!-- Distributed under the Boost -->
  1170. <!-- Software License, Version 1.0. (See accompanying -->
  1171. <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
  1172. <!-- Version 1.1 of this ReStructuredText document corresponds to
  1173. n1530_, the paper accepted by the LWG. -->
  1174. <!-- Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. -->
  1175. <p>Each specialization of the <tt class="docutils literal"><span class="pre">iterator_adaptor</span></tt> class template is derived from
  1176. a specialization of <tt class="docutils literal"><span class="pre">iterator_facade</span></tt>. The core interface functions
  1177. expected by <tt class="docutils literal"><span class="pre">iterator_facade</span></tt> are implemented in terms of the
  1178. <tt class="docutils literal"><span class="pre">iterator_adaptor</span></tt>'s <tt class="docutils literal"><span class="pre">Base</span></tt> template parameter. A class derived
  1179. from <tt class="docutils literal"><span class="pre">iterator_adaptor</span></tt> typically redefines some of the core
  1180. interface functions to adapt the behavior of the <tt class="docutils literal"><span class="pre">Base</span></tt> type.
  1181. Whether the derived class models any of the standard iterator concepts
  1182. depends on the operations supported by the <tt class="docutils literal"><span class="pre">Base</span></tt> type and which
  1183. core interface functions of <tt class="docutils literal"><span class="pre">iterator_facade</span></tt> are redefined in the
  1184. <tt class="docutils literal"><span class="pre">Derived</span></tt> class.</p>
  1185. <div class="section" id="class-template-iterator-adaptor">
  1186. <h3><a class="toc-backref" href="#id34">Class template <tt class="docutils literal"><span class="pre">iterator_adaptor</span></tt></a></h3>
  1187. <!-- Distributed under the Boost -->
  1188. <!-- Software License, Version 1.0. (See accompanying -->
  1189. <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
  1190. <!-- Version 1.4 of this ReStructuredText document corresponds to
  1191. n1530_, the paper accepted by the LWG for TR1. -->
  1192. <!-- Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2003. -->
  1193. <pre class="literal-block">
  1194. template &lt;
  1195. class Derived
  1196. , class Base
  1197. , class Value = use_default
  1198. , class CategoryOrTraversal = use_default
  1199. , class Reference = use_default
  1200. , class Difference = use_default
  1201. &gt;
  1202. class iterator_adaptor
  1203. : public iterator_facade&lt;Derived, <em>V'</em>, <em>C'</em>, <em>R'</em>, <em>D'</em>&gt; // see <a class="reference internal" href="#base-parameters">details</a>
  1204. {
  1205. friend class iterator_core_access;
  1206. public:
  1207. iterator_adaptor();
  1208. explicit iterator_adaptor(Base const&amp; iter);
  1209. typedef Base base_type;
  1210. Base const&amp; base() const;
  1211. protected:
  1212. typedef iterator_adaptor iterator_adaptor_;
  1213. Base const&amp; base_reference() const;
  1214. Base&amp; base_reference();
  1215. private: // Core iterator interface for iterator_facade.
  1216. typename iterator_adaptor::reference dereference() const;
  1217. template &lt;
  1218. class OtherDerived, class OtherIterator, class V, class C, class R, class D
  1219. &gt;
  1220. bool equal(iterator_adaptor&lt;OtherDerived, OtherIterator, V, C, R, D&gt; const&amp; x) const;
  1221. void advance(typename iterator_adaptor::difference_type n);
  1222. void increment();
  1223. void decrement();
  1224. template &lt;
  1225. class OtherDerived, class OtherIterator, class V, class C, class R, class D
  1226. &gt;
  1227. typename iterator_adaptor::difference_type distance_to(
  1228. iterator_adaptor&lt;OtherDerived, OtherIterator, V, C, R, D&gt; const&amp; y) const;
  1229. private:
  1230. Base m_iterator; // exposition only
  1231. };
  1232. </pre>
  1233. </div>
  1234. <div class="section" id="iterator-adaptor-requirements">
  1235. <span id="requirements"></span><h3><a class="toc-backref" href="#id35"><tt class="docutils literal"><span class="pre">iterator_adaptor</span></tt> requirements</a></h3>
  1236. <p><tt class="docutils literal"><span class="pre">static_cast&lt;Derived*&gt;(iterator_adaptor*)</span></tt> shall be well-formed.
  1237. The <tt class="docutils literal"><span class="pre">Base</span></tt> argument shall be Assignable and Copy Constructible.</p>
  1238. </div>
  1239. <div class="section" id="iterator-adaptor-base-class-parameters">
  1240. <span id="base-parameters"></span><h3><a class="toc-backref" href="#id36"><tt class="docutils literal"><span class="pre">iterator_adaptor</span></tt> base class parameters</a></h3>
  1241. <p>The <em>V'</em>, <em>C'</em>, <em>R'</em>, and <em>D'</em> parameters of the <tt class="docutils literal"><span class="pre">iterator_facade</span></tt>
  1242. used as a base class in the summary of <tt class="docutils literal"><span class="pre">iterator_adaptor</span></tt>
  1243. above are defined as follows:</p>
  1244. <pre class="literal-block">
  1245. <em>V'</em> = if (Value is use_default)
  1246. return iterator_traits&lt;Base&gt;::value_type
  1247. else
  1248. return Value
  1249. <em>C'</em> = if (CategoryOrTraversal is use_default)
  1250. return iterator_traversal&lt;Base&gt;::type
  1251. else
  1252. return CategoryOrTraversal
  1253. <em>R'</em> = if (Reference is use_default)
  1254. if (Value is use_default)
  1255. return iterator_traits&lt;Base&gt;::reference
  1256. else
  1257. return Value&amp;
  1258. else
  1259. return Reference
  1260. <em>D'</em> = if (Difference is use_default)
  1261. return iterator_traits&lt;Base&gt;::difference_type
  1262. else
  1263. return Difference
  1264. </pre>
  1265. <!-- ``iterator_adaptor`` models
  1266. - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1267. In order for ``Derived`` to model the iterator concepts corresponding
  1268. to ``iterator_traits<Derived>::iterator_category``, the expressions
  1269. involving ``m_iterator`` in the specifications of those private member
  1270. functions of ``iterator_adaptor`` that may be called by
  1271. ``iterator_facade<Derived, V, C, R, D>`` in evaluating any valid
  1272. expression involving ``Derived`` in those concepts' requirements. -->
  1273. <!-- The above is confusing and needs a rewrite. -JGS -->
  1274. <!-- That's why it's removed. We're embracing inheritance, remember? -->
  1275. </div>
  1276. <div class="section" id="iterator-adaptor-public-operations">
  1277. <h3><a class="toc-backref" href="#id37"><tt class="docutils literal"><span class="pre">iterator_adaptor</span></tt> public operations</a></h3>
  1278. <p><tt class="docutils literal"><span class="pre">iterator_adaptor();</span></tt></p>
  1279. <table class="docutils field-list" frame="void" rules="none">
  1280. <col class="field-name" />
  1281. <col class="field-body" />
  1282. <tbody valign="top">
  1283. <tr class="field"><th class="field-name">Requires:</th><td class="field-body">The <tt class="docutils literal"><span class="pre">Base</span></tt> type must be Default Constructible.</td>
  1284. </tr>
  1285. <tr class="field"><th class="field-name">Returns:</th><td class="field-body">An instance of <tt class="docutils literal"><span class="pre">iterator_adaptor</span></tt> with
  1286. <tt class="docutils literal"><span class="pre">m_iterator</span></tt> default constructed.</td>
  1287. </tr>
  1288. </tbody>
  1289. </table>
  1290. <p><tt class="docutils literal"><span class="pre">explicit</span> <span class="pre">iterator_adaptor(Base</span> <span class="pre">const&amp;</span> <span class="pre">iter);</span></tt></p>
  1291. <table class="docutils field-list" frame="void" rules="none">
  1292. <col class="field-name" />
  1293. <col class="field-body" />
  1294. <tbody valign="top">
  1295. <tr class="field"><th class="field-name">Returns:</th><td class="field-body">An instance of <tt class="docutils literal"><span class="pre">iterator_adaptor</span></tt> with
  1296. <tt class="docutils literal"><span class="pre">m_iterator</span></tt> copy constructed from <tt class="docutils literal"><span class="pre">iter</span></tt>.</td>
  1297. </tr>
  1298. </tbody>
  1299. </table>
  1300. <p><tt class="docutils literal"><span class="pre">Base</span> <span class="pre">const&amp;</span> <span class="pre">base()</span> <span class="pre">const;</span></tt></p>
  1301. <table class="docutils field-list" frame="void" rules="none">
  1302. <col class="field-name" />
  1303. <col class="field-body" />
  1304. <tbody valign="top">
  1305. <tr class="field"><th class="field-name">Returns:</th><td class="field-body"><tt class="docutils literal"><span class="pre">m_iterator</span></tt></td>
  1306. </tr>
  1307. </tbody>
  1308. </table>
  1309. </div>
  1310. <div class="section" id="iterator-adaptor-protected-member-functions">
  1311. <h3><a class="toc-backref" href="#id38"><tt class="docutils literal"><span class="pre">iterator_adaptor</span></tt> protected member functions</a></h3>
  1312. <p><tt class="docutils literal"><span class="pre">Base</span> <span class="pre">const&amp;</span> <span class="pre">base_reference()</span> <span class="pre">const;</span></tt></p>
  1313. <table class="docutils field-list" frame="void" rules="none">
  1314. <col class="field-name" />
  1315. <col class="field-body" />
  1316. <tbody valign="top">
  1317. <tr class="field"><th class="field-name">Returns:</th><td class="field-body">A const reference to <tt class="docutils literal"><span class="pre">m_iterator</span></tt>.</td>
  1318. </tr>
  1319. </tbody>
  1320. </table>
  1321. <p><tt class="docutils literal"><span class="pre">Base&amp;</span> <span class="pre">base_reference();</span></tt></p>
  1322. <table class="docutils field-list" frame="void" rules="none">
  1323. <col class="field-name" />
  1324. <col class="field-body" />
  1325. <tbody valign="top">
  1326. <tr class="field"><th class="field-name">Returns:</th><td class="field-body">A non-const reference to <tt class="docutils literal"><span class="pre">m_iterator</span></tt>.</td>
  1327. </tr>
  1328. </tbody>
  1329. </table>
  1330. </div>
  1331. <div class="section" id="iterator-adaptor-private-member-functions">
  1332. <h3><a class="toc-backref" href="#id39"><tt class="docutils literal"><span class="pre">iterator_adaptor</span></tt> private member functions</a></h3>
  1333. <p><tt class="docutils literal"><span class="pre">typename</span> <span class="pre">iterator_adaptor::reference</span> <span class="pre">dereference()</span> <span class="pre">const;</span></tt></p>
  1334. <table class="docutils field-list" frame="void" rules="none">
  1335. <col class="field-name" />
  1336. <col class="field-body" />
  1337. <tbody valign="top">
  1338. <tr class="field"><th class="field-name">Returns:</th><td class="field-body"><tt class="docutils literal"><span class="pre">*m_iterator</span></tt></td>
  1339. </tr>
  1340. </tbody>
  1341. </table>
  1342. <pre class="literal-block">
  1343. template &lt;
  1344. class OtherDerived, class OtherIterator, class V, class C, class R, class D
  1345. &gt;
  1346. bool equal(iterator_adaptor&lt;OtherDerived, OtherIterator, V, C, R, D&gt; const&amp; x) const;
  1347. </pre>
  1348. <table class="docutils field-list" frame="void" rules="none">
  1349. <col class="field-name" />
  1350. <col class="field-body" />
  1351. <tbody valign="top">
  1352. <tr class="field"><th class="field-name">Returns:</th><td class="field-body"><tt class="docutils literal"><span class="pre">m_iterator</span> <span class="pre">==</span> <span class="pre">x.base()</span></tt></td>
  1353. </tr>
  1354. </tbody>
  1355. </table>
  1356. <p><tt class="docutils literal"><span class="pre">void</span> <span class="pre">advance(typename</span> <span class="pre">iterator_adaptor::difference_type</span> <span class="pre">n);</span></tt></p>
  1357. <table class="docutils field-list" frame="void" rules="none">
  1358. <col class="field-name" />
  1359. <col class="field-body" />
  1360. <tbody valign="top">
  1361. <tr class="field"><th class="field-name">Effects:</th><td class="field-body"><tt class="docutils literal"><span class="pre">m_iterator</span> <span class="pre">+=</span> <span class="pre">n;</span></tt></td>
  1362. </tr>
  1363. </tbody>
  1364. </table>
  1365. <p><tt class="docutils literal"><span class="pre">void</span> <span class="pre">increment();</span></tt></p>
  1366. <table class="docutils field-list" frame="void" rules="none">
  1367. <col class="field-name" />
  1368. <col class="field-body" />
  1369. <tbody valign="top">
  1370. <tr class="field"><th class="field-name">Effects:</th><td class="field-body"><tt class="docutils literal"><span class="pre">++m_iterator;</span></tt></td>
  1371. </tr>
  1372. </tbody>
  1373. </table>
  1374. <p><tt class="docutils literal"><span class="pre">void</span> <span class="pre">decrement();</span></tt></p>
  1375. <table class="docutils field-list" frame="void" rules="none">
  1376. <col class="field-name" />
  1377. <col class="field-body" />
  1378. <tbody valign="top">
  1379. <tr class="field"><th class="field-name">Effects:</th><td class="field-body"><tt class="docutils literal"><span class="pre">--m_iterator;</span></tt></td>
  1380. </tr>
  1381. </tbody>
  1382. </table>
  1383. <pre class="literal-block">
  1384. template &lt;
  1385. class OtherDerived, class OtherIterator, class V, class C, class R, class D
  1386. &gt;
  1387. typename iterator_adaptor::difference_type distance_to(
  1388. iterator_adaptor&lt;OtherDerived, OtherIterator, V, C, R, D&gt; const&amp; y) const;
  1389. </pre>
  1390. <table class="docutils field-list" frame="void" rules="none">
  1391. <col class="field-name" />
  1392. <col class="field-body" />
  1393. <tbody valign="top">
  1394. <tr class="field"><th class="field-name">Returns:</th><td class="field-body"><tt class="docutils literal"><span class="pre">y.base()</span> <span class="pre">-</span> <span class="pre">m_iterator</span></tt></td>
  1395. </tr>
  1396. </tbody>
  1397. </table>
  1398. </div>
  1399. </div>
  1400. <div class="section" id="specialized-adaptors-lib-iterator-special-adaptors">
  1401. <h2><a class="toc-backref" href="#id40">Specialized adaptors [lib.iterator.special.adaptors]</a></h2>
  1402. <p>The <tt class="docutils literal"><span class="pre">enable_if_convertible&lt;X,Y&gt;::type</span></tt> expression used in
  1403. this section is for exposition purposes. The converting constructors
  1404. for specialized adaptors should be only be in an overload set provided
  1405. that an object of type <tt class="docutils literal"><span class="pre">X</span></tt> is implicitly convertible to an object of
  1406. type <tt class="docutils literal"><span class="pre">Y</span></tt>.
  1407. The signatures involving <tt class="docutils literal"><span class="pre">enable_if_convertible</span></tt> should behave
  1408. <em>as-if</em> <tt class="docutils literal"><span class="pre">enable_if_convertible</span></tt> were defined to be:</p>
  1409. <pre class="literal-block">
  1410. template &lt;bool&gt; enable_if_convertible_impl
  1411. {};
  1412. template &lt;&gt; enable_if_convertible_impl&lt;true&gt;
  1413. { struct type; };
  1414. template&lt;typename From, typename To&gt;
  1415. struct enable_if_convertible
  1416. : enable_if_convertible_impl&lt;is_convertible&lt;From,To&gt;::value&gt;
  1417. {};
  1418. </pre>
  1419. <p>If an expression other than the default argument is used to supply
  1420. the value of a function parameter whose type is written in terms
  1421. of <tt class="docutils literal"><span class="pre">enable_if_convertible</span></tt>, the program is ill-formed, no
  1422. diagnostic required.</p>
  1423. <p>[<em>Note:</em> The <tt class="docutils literal"><span class="pre">enable_if_convertible</span></tt> approach uses SFINAE to
  1424. take the constructor out of the overload set when the types are not
  1425. implicitly convertible.
  1426. ]</p>
  1427. <div class="section" id="indirect-iterator">
  1428. <h3><a class="toc-backref" href="#id41">Indirect iterator</a></h3>
  1429. <!-- Copyright David Abrahams 2006. Distributed under the Boost -->
  1430. <!-- Software License, Version 1.0. (See accompanying -->
  1431. <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
  1432. <p><tt class="docutils literal"><span class="pre">indirect_iterator</span></tt> adapts an iterator by applying an
  1433. <em>extra</em> dereference inside of <tt class="docutils literal"><span class="pre">operator*()</span></tt>. For example, this
  1434. iterator adaptor makes it possible to view a container of pointers
  1435. (e.g. <tt class="docutils literal"><span class="pre">list&lt;foo*&gt;</span></tt>) as if it were a container of the pointed-to type
  1436. (e.g. <tt class="docutils literal"><span class="pre">list&lt;foo&gt;</span></tt>). <tt class="docutils literal"><span class="pre">indirect_iterator</span></tt> depends on two
  1437. auxiliary traits, <tt class="docutils literal"><span class="pre">pointee</span></tt> and <tt class="docutils literal"><span class="pre">indirect_reference</span></tt>, to
  1438. provide support for underlying iterators whose <tt class="docutils literal"><span class="pre">value_type</span></tt> is
  1439. not an iterator.</p>
  1440. <div class="section" id="class-template-pointee">
  1441. <h4><a class="toc-backref" href="#id42">Class template <tt class="docutils literal"><span class="pre">pointee</span></tt></a></h4>
  1442. <!-- Copyright David Abrahams 2004. Use, modification and distribution is -->
  1443. <!-- subject to the Boost Software License, Version 1.0. (See accompanying -->
  1444. <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
  1445. <pre class="literal-block">
  1446. template &lt;class Dereferenceable&gt;
  1447. struct pointee
  1448. {
  1449. typedef /* see below */ type;
  1450. };
  1451. </pre>
  1452. <table class="docutils field-list" frame="void" rules="none">
  1453. <col class="field-name" />
  1454. <col class="field-body" />
  1455. <tbody valign="top">
  1456. <tr class="field"><th class="field-name">Requires:</th><td class="field-body">For an object <tt class="docutils literal"><span class="pre">x</span></tt> of type <tt class="docutils literal"><span class="pre">Dereferenceable</span></tt>, <tt class="docutils literal"><span class="pre">*x</span></tt>
  1457. is well-formed. If <tt class="docutils literal"><span class="pre">++x</span></tt> is ill-formed it shall neither be
  1458. ambiguous nor shall it violate access control, and
  1459. <tt class="docutils literal"><span class="pre">Dereferenceable::element_type</span></tt> shall be an accessible type.
  1460. Otherwise <tt class="docutils literal"><span class="pre">iterator_traits&lt;Dereferenceable&gt;::value_type</span></tt> shall
  1461. be well formed. [Note: These requirements need not apply to
  1462. explicit or partial specializations of <tt class="docutils literal"><span class="pre">pointee</span></tt>]</td>
  1463. </tr>
  1464. </tbody>
  1465. </table>
  1466. <p><tt class="docutils literal"><span class="pre">type</span></tt> is determined according to the following algorithm, where
  1467. <tt class="docutils literal"><span class="pre">x</span></tt> is an object of type <tt class="docutils literal"><span class="pre">Dereferenceable</span></tt>:</p>
  1468. <pre class="literal-block">
  1469. if ( ++x is ill-formed )
  1470. {
  1471. return ``Dereferenceable::element_type``
  1472. }
  1473. else if (``*x`` is a mutable reference to
  1474. std::iterator_traits&lt;Dereferenceable&gt;::value_type)
  1475. {
  1476. return iterator_traits&lt;Dereferenceable&gt;::value_type
  1477. }
  1478. else
  1479. {
  1480. return iterator_traits&lt;Dereferenceable&gt;::value_type const
  1481. }
  1482. </pre>
  1483. </div>
  1484. <div class="section" id="class-template-indirect-reference">
  1485. <h4><a class="toc-backref" href="#id43">Class template <tt class="docutils literal"><span class="pre">indirect_reference</span></tt></a></h4>
  1486. <!-- Copyright David Abrahams 2004. Use, modification and distribution is -->
  1487. <!-- subject to the Boost Software License, Version 1.0. (See accompanying -->
  1488. <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
  1489. <pre class="literal-block">
  1490. template &lt;class Dereferenceable&gt;
  1491. struct indirect_reference
  1492. {
  1493. typedef /* see below */ type;
  1494. };
  1495. </pre>
  1496. <table class="docutils field-list" frame="void" rules="none">
  1497. <col class="field-name" />
  1498. <col class="field-body" />
  1499. <tbody valign="top">
  1500. <tr class="field"><th class="field-name">Requires:</th><td class="field-body">For an object <tt class="docutils literal"><span class="pre">x</span></tt> of type <tt class="docutils literal"><span class="pre">Dereferenceable</span></tt>, <tt class="docutils literal"><span class="pre">*x</span></tt>
  1501. is well-formed. If <tt class="docutils literal"><span class="pre">++x</span></tt> is ill-formed it shall neither be
  1502. ambiguous nor shall it violate access control, and
  1503. <tt class="docutils literal"><span class="pre">pointee&lt;Dereferenceable&gt;::type&amp;</span></tt> shall be well-formed.
  1504. Otherwise <tt class="docutils literal"><span class="pre">iterator_traits&lt;Dereferenceable&gt;::reference</span></tt> shall
  1505. be well formed. [Note: These requirements need not apply to
  1506. explicit or partial specializations of <tt class="docutils literal"><span class="pre">indirect_reference</span></tt>]</td>
  1507. </tr>
  1508. </tbody>
  1509. </table>
  1510. <p><tt class="docutils literal"><span class="pre">type</span></tt> is determined according to the following algorithm, where
  1511. <tt class="docutils literal"><span class="pre">x</span></tt> is an object of type <tt class="docutils literal"><span class="pre">Dereferenceable</span></tt>:</p>
  1512. <pre class="literal-block">
  1513. if ( ++x is ill-formed )
  1514. return ``pointee&lt;Dereferenceable&gt;::type&amp;``
  1515. else
  1516. std::iterator_traits&lt;Dereferenceable&gt;::reference
  1517. </pre>
  1518. </div>
  1519. <div class="section" id="class-template-indirect-iterator">
  1520. <h4><a class="toc-backref" href="#id44">Class template <tt class="docutils literal"><span class="pre">indirect_iterator</span></tt></a></h4>
  1521. <!-- Copyright David Abrahams 2006. Distributed under the Boost -->
  1522. <!-- Software License, Version 1.0. (See accompanying -->
  1523. <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
  1524. <pre class="literal-block">
  1525. template &lt;
  1526. class Iterator
  1527. , class Value = use_default
  1528. , class CategoryOrTraversal = use_default
  1529. , class Reference = use_default
  1530. , class Difference = use_default
  1531. &gt;
  1532. class indirect_iterator
  1533. {
  1534. public:
  1535. typedef /* see below */ value_type;
  1536. typedef /* see below */ reference;
  1537. typedef /* see below */ pointer;
  1538. typedef /* see below */ difference_type;
  1539. typedef /* see below */ iterator_category;
  1540. indirect_iterator();
  1541. indirect_iterator(Iterator x);
  1542. template &lt;
  1543. class Iterator2, class Value2, class Category2
  1544. , class Reference2, class Difference2
  1545. &gt;
  1546. indirect_iterator(
  1547. indirect_iterator&lt;
  1548. Iterator2, Value2, Category2, Reference2, Difference2
  1549. &gt; const&amp; y
  1550. , typename enable_if_convertible&lt;Iterator2, Iterator&gt;::type* = 0 // exposition
  1551. );
  1552. Iterator const&amp; base() const;
  1553. reference operator*() const;
  1554. indirect_iterator&amp; operator++();
  1555. indirect_iterator&amp; operator--();
  1556. private:
  1557. Iterator m_iterator; // exposition
  1558. };
  1559. </pre>
  1560. <p>The member types of <tt class="docutils literal"><span class="pre">indirect_iterator</span></tt> are defined according to
  1561. the following pseudo-code, where <tt class="docutils literal"><span class="pre">V</span></tt> is
  1562. <tt class="docutils literal"><span class="pre">iterator_traits&lt;Iterator&gt;::value_type</span></tt></p>
  1563. <pre class="literal-block">
  1564. if (Value is use_default) then
  1565. typedef remove_const&lt;pointee&lt;V&gt;::type&gt;::type value_type;
  1566. else
  1567. typedef remove_const&lt;Value&gt;::type value_type;
  1568. if (Reference is use_default) then
  1569. if (Value is use_default) then
  1570. typedef indirect_reference&lt;V&gt;::type reference;
  1571. else
  1572. typedef Value&amp; reference;
  1573. else
  1574. typedef Reference reference;
  1575. if (Value is use_default) then
  1576. typedef pointee&lt;V&gt;::type* pointer;
  1577. else
  1578. typedef Value* pointer;
  1579. if (Difference is use_default)
  1580. typedef iterator_traits&lt;Iterator&gt;::difference_type difference_type;
  1581. else
  1582. typedef Difference difference_type;
  1583. if (CategoryOrTraversal is use_default)
  1584. typedef <em>iterator-category</em> (
  1585. iterator_traversal&lt;Iterator&gt;::type,``reference``,``value_type``
  1586. ) iterator_category;
  1587. else
  1588. typedef <em>iterator-category</em> (
  1589. CategoryOrTraversal,``reference``,``value_type``
  1590. ) iterator_category;
  1591. </pre>
  1592. </div>
  1593. <div class="section" id="indirect-iterator-requirements">
  1594. <h4><a class="toc-backref" href="#id45"><tt class="docutils literal"><span class="pre">indirect_iterator</span></tt> requirements</a></h4>
  1595. <p>The expression <tt class="docutils literal"><span class="pre">*v</span></tt>, where <tt class="docutils literal"><span class="pre">v</span></tt> is an object of
  1596. <tt class="docutils literal"><span class="pre">iterator_traits&lt;Iterator&gt;::value_type</span></tt>, shall be valid
  1597. expression and convertible to <tt class="docutils literal"><span class="pre">reference</span></tt>. <tt class="docutils literal"><span class="pre">Iterator</span></tt> shall
  1598. model the traversal concept indicated by <tt class="docutils literal"><span class="pre">iterator_category</span></tt>.
  1599. <tt class="docutils literal"><span class="pre">Value</span></tt>, <tt class="docutils literal"><span class="pre">Reference</span></tt>, and <tt class="docutils literal"><span class="pre">Difference</span></tt> shall be chosen so
  1600. that <tt class="docutils literal"><span class="pre">value_type</span></tt>, <tt class="docutils literal"><span class="pre">reference</span></tt>, and <tt class="docutils literal"><span class="pre">difference_type</span></tt> meet
  1601. the requirements indicated by <tt class="docutils literal"><span class="pre">iterator_category</span></tt>.</p>
  1602. <p>[Note: there are further requirements on the
  1603. <tt class="docutils literal"><span class="pre">iterator_traits&lt;Iterator&gt;::value_type</span></tt> if the <tt class="docutils literal"><span class="pre">Value</span></tt>
  1604. parameter is not <tt class="docutils literal"><span class="pre">use_default</span></tt>, as implied by the algorithm for
  1605. deducing the default for the <tt class="docutils literal"><span class="pre">value_type</span></tt> member.]</p>
  1606. </div>
  1607. <div class="section" id="indirect-iterator-models">
  1608. <h4><a class="toc-backref" href="#id46"><tt class="docutils literal"><span class="pre">indirect_iterator</span></tt> models</a></h4>
  1609. <p>In addition to the concepts indicated by <tt class="docutils literal"><span class="pre">iterator_category</span></tt>
  1610. and by <tt class="docutils literal"><span class="pre">iterator_traversal&lt;indirect_iterator&gt;::type</span></tt>, a
  1611. specialization of <tt class="docutils literal"><span class="pre">indirect_iterator</span></tt> models the following
  1612. concepts, Where <tt class="docutils literal"><span class="pre">v</span></tt> is an object of
  1613. <tt class="docutils literal"><span class="pre">iterator_traits&lt;Iterator&gt;::value_type</span></tt>:</p>
  1614. <blockquote>
  1615. <ul class="simple">
  1616. <li>Readable Iterator if <tt class="docutils literal"><span class="pre">reference(*v)</span></tt> is convertible to
  1617. <tt class="docutils literal"><span class="pre">value_type</span></tt>.</li>
  1618. <li>Writable Iterator if <tt class="docutils literal"><span class="pre">reference(*v)</span> <span class="pre">=</span> <span class="pre">t</span></tt> is a valid
  1619. expression (where <tt class="docutils literal"><span class="pre">t</span></tt> is an object of type
  1620. <tt class="docutils literal"><span class="pre">indirect_iterator::value_type</span></tt>)</li>
  1621. <li>Lvalue Iterator if <tt class="docutils literal"><span class="pre">reference</span></tt> is a reference type.</li>
  1622. </ul>
  1623. </blockquote>
  1624. <p><tt class="docutils literal"><span class="pre">indirect_iterator&lt;X,V1,C1,R1,D1&gt;</span></tt> is interoperable with
  1625. <tt class="docutils literal"><span class="pre">indirect_iterator&lt;Y,V2,C2,R2,D2&gt;</span></tt> if and only if <tt class="docutils literal"><span class="pre">X</span></tt> is
  1626. interoperable with <tt class="docutils literal"><span class="pre">Y</span></tt>.</p>
  1627. </div>
  1628. <div class="section" id="indirect-iterator-operations">
  1629. <h4><a class="toc-backref" href="#id47"><tt class="docutils literal"><span class="pre">indirect_iterator</span></tt> operations</a></h4>
  1630. <p>In addition to the operations required by the concepts described
  1631. above, specializations of <tt class="docutils literal"><span class="pre">indirect_iterator</span></tt> provide the
  1632. following operations.</p>
  1633. <p><tt class="docutils literal"><span class="pre">indirect_iterator();</span></tt></p>
  1634. <table class="docutils field-list" frame="void" rules="none">
  1635. <col class="field-name" />
  1636. <col class="field-body" />
  1637. <tbody valign="top">
  1638. <tr class="field"><th class="field-name">Requires:</th><td class="field-body"><tt class="docutils literal"><span class="pre">Iterator</span></tt> must be Default Constructible.</td>
  1639. </tr>
  1640. <tr class="field"><th class="field-name">Effects:</th><td class="field-body">Constructs an instance of <tt class="docutils literal"><span class="pre">indirect_iterator</span></tt> with
  1641. a default-constructed <tt class="docutils literal"><span class="pre">m_iterator</span></tt>.</td>
  1642. </tr>
  1643. </tbody>
  1644. </table>
  1645. <p><tt class="docutils literal"><span class="pre">indirect_iterator(Iterator</span> <span class="pre">x);</span></tt></p>
  1646. <table class="docutils field-list" frame="void" rules="none">
  1647. <col class="field-name" />
  1648. <col class="field-body" />
  1649. <tbody valign="top">
  1650. <tr class="field"><th class="field-name">Effects:</th><td class="field-body">Constructs an instance of <tt class="docutils literal"><span class="pre">indirect_iterator</span></tt> with
  1651. <tt class="docutils literal"><span class="pre">m_iterator</span></tt> copy constructed from <tt class="docutils literal"><span class="pre">x</span></tt>.</td>
  1652. </tr>
  1653. </tbody>
  1654. </table>
  1655. <pre class="literal-block">
  1656. template &lt;
  1657. class Iterator2, class Value2, unsigned Access, class Traversal
  1658. , class Reference2, class Difference2
  1659. &gt;
  1660. indirect_iterator(
  1661. indirect_iterator&lt;
  1662. Iterator2, Value2, Access, Traversal, Reference2, Difference2
  1663. &gt; const&amp; y
  1664. , typename enable_if_convertible&lt;Iterator2, Iterator&gt;::type* = 0 // exposition
  1665. );
  1666. </pre>
  1667. <table class="docutils field-list" frame="void" rules="none">
  1668. <col class="field-name" />
  1669. <col class="field-body" />
  1670. <tbody valign="top">
  1671. <tr class="field"><th class="field-name">Requires:</th><td class="field-body"><tt class="docutils literal"><span class="pre">Iterator2</span></tt> is implicitly convertible to <tt class="docutils literal"><span class="pre">Iterator</span></tt>.</td>
  1672. </tr>
  1673. <tr class="field"><th class="field-name">Effects:</th><td class="field-body">Constructs an instance of <tt class="docutils literal"><span class="pre">indirect_iterator</span></tt> whose
  1674. <tt class="docutils literal"><span class="pre">m_iterator</span></tt> subobject is constructed from <tt class="docutils literal"><span class="pre">y.base()</span></tt>.</td>
  1675. </tr>
  1676. </tbody>
  1677. </table>
  1678. <p><tt class="docutils literal"><span class="pre">Iterator</span> <span class="pre">const&amp;</span> <span class="pre">base()</span> <span class="pre">const;</span></tt></p>
  1679. <table class="docutils field-list" frame="void" rules="none">
  1680. <col class="field-name" />
  1681. <col class="field-body" />
  1682. <tbody valign="top">
  1683. <tr class="field"><th class="field-name">Returns:</th><td class="field-body"><tt class="docutils literal"><span class="pre">m_iterator</span></tt></td>
  1684. </tr>
  1685. </tbody>
  1686. </table>
  1687. <p><tt class="docutils literal"><span class="pre">reference</span> <span class="pre">operator*()</span> <span class="pre">const;</span></tt></p>
  1688. <table class="docutils field-list" frame="void" rules="none">
  1689. <col class="field-name" />
  1690. <col class="field-body" />
  1691. <tbody valign="top">
  1692. <tr class="field"><th class="field-name">Returns:</th><td class="field-body"><tt class="docutils literal"><span class="pre">**m_iterator</span></tt></td>
  1693. </tr>
  1694. </tbody>
  1695. </table>
  1696. <p><tt class="docutils literal"><span class="pre">indirect_iterator&amp;</span> <span class="pre">operator++();</span></tt></p>
  1697. <table class="docutils field-list" frame="void" rules="none">
  1698. <col class="field-name" />
  1699. <col class="field-body" />
  1700. <tbody valign="top">
  1701. <tr class="field"><th class="field-name">Effects:</th><td class="field-body"><tt class="docutils literal"><span class="pre">++m_iterator</span></tt></td>
  1702. </tr>
  1703. <tr class="field"><th class="field-name">Returns:</th><td class="field-body"><tt class="docutils literal"><span class="pre">*this</span></tt></td>
  1704. </tr>
  1705. </tbody>
  1706. </table>
  1707. <p><tt class="docutils literal"><span class="pre">indirect_iterator&amp;</span> <span class="pre">operator--();</span></tt></p>
  1708. <table class="docutils field-list" frame="void" rules="none">
  1709. <col class="field-name" />
  1710. <col class="field-body" />
  1711. <tbody valign="top">
  1712. <tr class="field"><th class="field-name">Effects:</th><td class="field-body"><tt class="docutils literal"><span class="pre">--m_iterator</span></tt></td>
  1713. </tr>
  1714. <tr class="field"><th class="field-name">Returns:</th><td class="field-body"><tt class="docutils literal"><span class="pre">*this</span></tt></td>
  1715. </tr>
  1716. </tbody>
  1717. </table>
  1718. </div>
  1719. </div>
  1720. <div class="section" id="reverse-iterator">
  1721. <h3><a class="toc-backref" href="#id48">Reverse iterator</a></h3>
  1722. <!-- Copyright David Abrahams 2006. Distributed under the Boost -->
  1723. <!-- Software License, Version 1.0. (See accompanying -->
  1724. <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
  1725. <p>The reverse iterator adaptor iterates through the adapted iterator
  1726. range in the opposite direction.</p>
  1727. <div class="section" id="class-template-reverse-iterator">
  1728. <h4><a class="toc-backref" href="#id49">Class template <tt class="docutils literal"><span class="pre">reverse_iterator</span></tt></a></h4>
  1729. <!-- Copyright David Abrahams 2006. Distributed under the Boost -->
  1730. <!-- Software License, Version 1.0. (See accompanying -->
  1731. <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
  1732. <pre class="literal-block">
  1733. template &lt;class Iterator&gt;
  1734. class reverse_iterator
  1735. {
  1736. public:
  1737. typedef iterator_traits&lt;Iterator&gt;::value_type value_type;
  1738. typedef iterator_traits&lt;Iterator&gt;::reference reference;
  1739. typedef iterator_traits&lt;Iterator&gt;::pointer pointer;
  1740. typedef iterator_traits&lt;Iterator&gt;::difference_type difference_type;
  1741. typedef /* see below */ iterator_category;
  1742. reverse_iterator() {}
  1743. explicit reverse_iterator(Iterator x) ;
  1744. template&lt;class OtherIterator&gt;
  1745. reverse_iterator(
  1746. reverse_iterator&lt;OtherIterator&gt; const&amp; r
  1747. , typename enable_if_convertible&lt;OtherIterator, Iterator&gt;::type* = 0 // exposition
  1748. );
  1749. Iterator const&amp; base() const;
  1750. reference operator*() const;
  1751. reverse_iterator&amp; operator++();
  1752. reverse_iterator&amp; operator--();
  1753. private:
  1754. Iterator m_iterator; // exposition
  1755. };
  1756. </pre>
  1757. <p>If <tt class="docutils literal"><span class="pre">Iterator</span></tt> models Random Access Traversal Iterator and Readable
  1758. Lvalue Iterator, then <tt class="docutils literal"><span class="pre">iterator_category</span></tt> is convertible to
  1759. <tt class="docutils literal"><span class="pre">random_access_iterator_tag</span></tt>. Otherwise, if
  1760. <tt class="docutils literal"><span class="pre">Iterator</span></tt> models Bidirectional Traversal Iterator and Readable
  1761. Lvalue Iterator, then <tt class="docutils literal"><span class="pre">iterator_category</span></tt> is convertible to
  1762. <tt class="docutils literal"><span class="pre">bidirectional_iterator_tag</span></tt>. Otherwise, <tt class="docutils literal"><span class="pre">iterator_category</span></tt> is
  1763. convertible to <tt class="docutils literal"><span class="pre">input_iterator_tag</span></tt>.</p>
  1764. </div>
  1765. <div class="section" id="reverse-iterator-requirements">
  1766. <h4><a class="toc-backref" href="#id50"><tt class="docutils literal"><span class="pre">reverse_iterator</span></tt> requirements</a></h4>
  1767. <p><tt class="docutils literal"><span class="pre">Iterator</span></tt> must be a model of Bidirectional Traversal Iterator. The
  1768. type <tt class="docutils literal"><span class="pre">iterator_traits&lt;Iterator&gt;::reference</span></tt> must be the type of
  1769. <tt class="docutils literal"><span class="pre">*i</span></tt>, where <tt class="docutils literal"><span class="pre">i</span></tt> is an object of type <tt class="docutils literal"><span class="pre">Iterator</span></tt>.</p>
  1770. </div>
  1771. <div class="section" id="reverse-iterator-models">
  1772. <h4><a class="toc-backref" href="#id51"><tt class="docutils literal"><span class="pre">reverse_iterator</span></tt> models</a></h4>
  1773. <p>A specialization of <tt class="docutils literal"><span class="pre">reverse_iterator</span></tt> models the same iterator
  1774. traversal and iterator access concepts modeled by its <tt class="docutils literal"><span class="pre">Iterator</span></tt>
  1775. argument. In addition, it may model old iterator concepts
  1776. specified in the following table:</p>
  1777. <table border="1" class="docutils">
  1778. <colgroup>
  1779. <col width="53%" />
  1780. <col width="47%" />
  1781. </colgroup>
  1782. <thead valign="bottom">
  1783. <tr><th class="head">If <tt class="docutils literal"><span class="pre">I</span></tt> models</th>
  1784. <th class="head">then <tt class="docutils literal"><span class="pre">reverse_iterator&lt;I&gt;</span></tt> models</th>
  1785. </tr>
  1786. </thead>
  1787. <tbody valign="top">
  1788. <tr><td>Readable Lvalue Iterator,
  1789. Bidirectional Traversal Iterator</td>
  1790. <td>Bidirectional Iterator</td>
  1791. </tr>
  1792. <tr><td>Writable Lvalue Iterator,
  1793. Bidirectional Traversal Iterator</td>
  1794. <td>Mutable Bidirectional Iterator</td>
  1795. </tr>
  1796. <tr><td>Readable Lvalue Iterator,
  1797. Random Access Traversal Iterator</td>
  1798. <td>Random Access Iterator</td>
  1799. </tr>
  1800. <tr><td>Writable Lvalue Iterator,
  1801. Random Access Traversal Iterator</td>
  1802. <td>Mutable Random Access Iterator</td>
  1803. </tr>
  1804. </tbody>
  1805. </table>
  1806. <p><tt class="docutils literal"><span class="pre">reverse_iterator&lt;X&gt;</span></tt> is interoperable with
  1807. <tt class="docutils literal"><span class="pre">reverse_iterator&lt;Y&gt;</span></tt> if and only if <tt class="docutils literal"><span class="pre">X</span></tt> is interoperable with
  1808. <tt class="docutils literal"><span class="pre">Y</span></tt>.</p>
  1809. </div>
  1810. <div class="section" id="reverse-iterator-operations">
  1811. <h4><a class="toc-backref" href="#id52"><tt class="docutils literal"><span class="pre">reverse_iterator</span></tt> operations</a></h4>
  1812. <p>In addition to the operations required by the concepts modeled by
  1813. <tt class="docutils literal"><span class="pre">reverse_iterator</span></tt>, <tt class="docutils literal"><span class="pre">reverse_iterator</span></tt> provides the following
  1814. operations.</p>
  1815. <p><tt class="docutils literal"><span class="pre">reverse_iterator();</span></tt></p>
  1816. <table class="docutils field-list" frame="void" rules="none">
  1817. <col class="field-name" />
  1818. <col class="field-body" />
  1819. <tbody valign="top">
  1820. <tr class="field"><th class="field-name">Requires:</th><td class="field-body"><tt class="docutils literal"><span class="pre">Iterator</span></tt> must be Default Constructible.</td>
  1821. </tr>
  1822. <tr class="field"><th class="field-name">Effects:</th><td class="field-body">Constructs an instance of <tt class="docutils literal"><span class="pre">reverse_iterator</span></tt> with <tt class="docutils literal"><span class="pre">m_iterator</span></tt>
  1823. default constructed.</td>
  1824. </tr>
  1825. </tbody>
  1826. </table>
  1827. <p><tt class="docutils literal"><span class="pre">explicit</span> <span class="pre">reverse_iterator(Iterator</span> <span class="pre">x);</span></tt></p>
  1828. <table class="docutils field-list" frame="void" rules="none">
  1829. <col class="field-name" />
  1830. <col class="field-body" />
  1831. <tbody valign="top">
  1832. <tr class="field"><th class="field-name">Effects:</th><td class="field-body">Constructs an instance of <tt class="docutils literal"><span class="pre">reverse_iterator</span></tt> with
  1833. <tt class="docutils literal"><span class="pre">m_iterator</span></tt> copy constructed from <tt class="docutils literal"><span class="pre">x</span></tt>.</td>
  1834. </tr>
  1835. </tbody>
  1836. </table>
  1837. <pre class="literal-block">
  1838. template&lt;class OtherIterator&gt;
  1839. reverse_iterator(
  1840. reverse_iterator&lt;OtherIterator&gt; const&amp; r
  1841. , typename enable_if_convertible&lt;OtherIterator, Iterator&gt;::type* = 0 // exposition
  1842. );
  1843. </pre>
  1844. <table class="docutils field-list" frame="void" rules="none">
  1845. <col class="field-name" />
  1846. <col class="field-body" />
  1847. <tbody valign="top">
  1848. <tr class="field"><th class="field-name">Requires:</th><td class="field-body"><tt class="docutils literal"><span class="pre">OtherIterator</span></tt> is implicitly convertible to <tt class="docutils literal"><span class="pre">Iterator</span></tt>.</td>
  1849. </tr>
  1850. <tr class="field"><th class="field-name">Effects:</th><td class="field-body">Constructs instance of <tt class="docutils literal"><span class="pre">reverse_iterator</span></tt> whose
  1851. <tt class="docutils literal"><span class="pre">m_iterator</span></tt> subobject is constructed from <tt class="docutils literal"><span class="pre">y.base()</span></tt>.</td>
  1852. </tr>
  1853. </tbody>
  1854. </table>
  1855. <p><tt class="docutils literal"><span class="pre">Iterator</span> <span class="pre">const&amp;</span> <span class="pre">base()</span> <span class="pre">const;</span></tt></p>
  1856. <table class="docutils field-list" frame="void" rules="none">
  1857. <col class="field-name" />
  1858. <col class="field-body" />
  1859. <tbody valign="top">
  1860. <tr class="field"><th class="field-name">Returns:</th><td class="field-body"><tt class="docutils literal"><span class="pre">m_iterator</span></tt></td>
  1861. </tr>
  1862. </tbody>
  1863. </table>
  1864. <p><tt class="docutils literal"><span class="pre">reference</span> <span class="pre">operator*()</span> <span class="pre">const;</span></tt></p>
  1865. <table class="docutils field-list" frame="void" rules="none">
  1866. <col class="field-name" />
  1867. <col class="field-body" />
  1868. <tbody valign="top">
  1869. <tr class="field"><th class="field-name">Effects:</th><td class="field-body"></td>
  1870. </tr>
  1871. </tbody>
  1872. </table>
  1873. <pre class="literal-block">
  1874. Iterator tmp = m_iterator;
  1875. return *--tmp;
  1876. </pre>
  1877. <p><tt class="docutils literal"><span class="pre">reverse_iterator&amp;</span> <span class="pre">operator++();</span></tt></p>
  1878. <table class="docutils field-list" frame="void" rules="none">
  1879. <col class="field-name" />
  1880. <col class="field-body" />
  1881. <tbody valign="top">
  1882. <tr class="field"><th class="field-name">Effects:</th><td class="field-body"><tt class="docutils literal"><span class="pre">--m_iterator</span></tt></td>
  1883. </tr>
  1884. <tr class="field"><th class="field-name">Returns:</th><td class="field-body"><tt class="docutils literal"><span class="pre">*this</span></tt></td>
  1885. </tr>
  1886. </tbody>
  1887. </table>
  1888. <p><tt class="docutils literal"><span class="pre">reverse_iterator&amp;</span> <span class="pre">operator--();</span></tt></p>
  1889. <table class="docutils field-list" frame="void" rules="none">
  1890. <col class="field-name" />
  1891. <col class="field-body" />
  1892. <tbody valign="top">
  1893. <tr class="field"><th class="field-name">Effects:</th><td class="field-body"><tt class="docutils literal"><span class="pre">++m_iterator</span></tt></td>
  1894. </tr>
  1895. <tr class="field"><th class="field-name">Returns:</th><td class="field-body"><tt class="docutils literal"><span class="pre">*this</span></tt></td>
  1896. </tr>
  1897. </tbody>
  1898. </table>
  1899. </div>
  1900. </div>
  1901. <div class="section" id="transform-iterator">
  1902. <h3><a class="toc-backref" href="#id53">Transform iterator</a></h3>
  1903. <!-- Copyright David Abrahams 2006. Distributed under the Boost -->
  1904. <!-- Software License, Version 1.0. (See accompanying -->
  1905. <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
  1906. <p>The transform iterator adapts an iterator by modifying the
  1907. <tt class="docutils literal"><span class="pre">operator*</span></tt> to apply a function object to the result of
  1908. dereferencing the iterator and returning the result.</p>
  1909. <div class="section" id="class-template-transform-iterator">
  1910. <h4><a class="toc-backref" href="#id54">Class template <tt class="docutils literal"><span class="pre">transform_iterator</span></tt></a></h4>
  1911. <!-- Copyright David Abrahams 2006. Distributed under the Boost -->
  1912. <!-- Software License, Version 1.0. (See accompanying -->
  1913. <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
  1914. <!-- Version 1.3 of this document was accepted for TR1 -->
  1915. <pre class="literal-block">
  1916. template &lt;class UnaryFunction,
  1917. class Iterator,
  1918. class Reference = use_default,
  1919. class Value = use_default&gt;
  1920. class transform_iterator
  1921. {
  1922. public:
  1923. typedef /* see below */ value_type;
  1924. typedef /* see below */ reference;
  1925. typedef /* see below */ pointer;
  1926. typedef iterator_traits&lt;Iterator&gt;::difference_type difference_type;
  1927. typedef /* see below */ iterator_category;
  1928. transform_iterator();
  1929. transform_iterator(Iterator const&amp; x, UnaryFunction f);
  1930. template&lt;class F2, class I2, class R2, class V2&gt;
  1931. transform_iterator(
  1932. transform_iterator&lt;F2, I2, R2, V2&gt; const&amp; t
  1933. , typename enable_if_convertible&lt;I2, Iterator&gt;::type* = 0 // exposition only
  1934. , typename enable_if_convertible&lt;F2, UnaryFunction&gt;::type* = 0 // exposition only
  1935. );
  1936. UnaryFunction functor() const;
  1937. Iterator const&amp; base() const;
  1938. reference operator*() const;
  1939. transform_iterator&amp; operator++();
  1940. transform_iterator&amp; operator--();
  1941. private:
  1942. Iterator m_iterator; // exposition only
  1943. UnaryFunction m_f; // exposition only
  1944. };
  1945. </pre>
  1946. <p>If <tt class="docutils literal"><span class="pre">Reference</span></tt> is <tt class="docutils literal"><span class="pre">use_default</span></tt> then the <tt class="docutils literal"><span class="pre">reference</span></tt> member of
  1947. <tt class="docutils literal"><span class="pre">transform_iterator</span></tt> is
  1948. <tt class="docutils literal"><span class="pre">result_of&lt;UnaryFunction(iterator_traits&lt;Iterator&gt;::reference)&gt;::type</span></tt>.
  1949. Otherwise, <tt class="docutils literal"><span class="pre">reference</span></tt> is <tt class="docutils literal"><span class="pre">Reference</span></tt>.</p>
  1950. <p>If <tt class="docutils literal"><span class="pre">Value</span></tt> is <tt class="docutils literal"><span class="pre">use_default</span></tt> then the <tt class="docutils literal"><span class="pre">value_type</span></tt> member is
  1951. <tt class="docutils literal"><span class="pre">remove_cv&lt;remove_reference&lt;reference&gt;</span> <span class="pre">&gt;::type</span></tt>. Otherwise,
  1952. <tt class="docutils literal"><span class="pre">value_type</span></tt> is <tt class="docutils literal"><span class="pre">Value</span></tt>.</p>
  1953. <p>If <tt class="docutils literal"><span class="pre">Iterator</span></tt> models Readable Lvalue Iterator and if <tt class="docutils literal"><span class="pre">Iterator</span></tt>
  1954. models Random Access Traversal Iterator, then <tt class="docutils literal"><span class="pre">iterator_category</span></tt> is
  1955. convertible to <tt class="docutils literal"><span class="pre">random_access_iterator_tag</span></tt>. Otherwise, if
  1956. <tt class="docutils literal"><span class="pre">Iterator</span></tt> models Bidirectional Traversal Iterator, then
  1957. <tt class="docutils literal"><span class="pre">iterator_category</span></tt> is convertible to
  1958. <tt class="docutils literal"><span class="pre">bidirectional_iterator_tag</span></tt>. Otherwise <tt class="docutils literal"><span class="pre">iterator_category</span></tt> is
  1959. convertible to <tt class="docutils literal"><span class="pre">forward_iterator_tag</span></tt>. If <tt class="docutils literal"><span class="pre">Iterator</span></tt> does not
  1960. model Readable Lvalue Iterator then <tt class="docutils literal"><span class="pre">iterator_category</span></tt> is
  1961. convertible to <tt class="docutils literal"><span class="pre">input_iterator_tag</span></tt>.</p>
  1962. </div>
  1963. <div class="section" id="transform-iterator-requirements">
  1964. <h4><a class="toc-backref" href="#id55"><tt class="docutils literal"><span class="pre">transform_iterator</span></tt> requirements</a></h4>
  1965. <p>The type <tt class="docutils literal"><span class="pre">UnaryFunction</span></tt> must be Assignable, Copy Constructible, and
  1966. the expression <tt class="docutils literal"><span class="pre">f(*i)</span></tt> must be valid where <tt class="docutils literal"><span class="pre">f</span></tt> is an object of
  1967. type <tt class="docutils literal"><span class="pre">UnaryFunction</span></tt>, <tt class="docutils literal"><span class="pre">i</span></tt> is an object of type <tt class="docutils literal"><span class="pre">Iterator</span></tt>, and
  1968. where the type of <tt class="docutils literal"><span class="pre">f(*i)</span></tt> must be
  1969. <tt class="docutils literal"><span class="pre">result_of&lt;UnaryFunction(iterator_traits&lt;Iterator&gt;::reference)&gt;::type</span></tt>.</p>
  1970. <p>The argument <tt class="docutils literal"><span class="pre">Iterator</span></tt> shall model Readable Iterator.</p>
  1971. </div>
  1972. <div class="section" id="transform-iterator-models">
  1973. <h4><a class="toc-backref" href="#id56"><tt class="docutils literal"><span class="pre">transform_iterator</span></tt> models</a></h4>
  1974. <p>The resulting <tt class="docutils literal"><span class="pre">transform_iterator</span></tt> models the most refined of the
  1975. following that is also modeled by <tt class="docutils literal"><span class="pre">Iterator</span></tt>.</p>
  1976. <blockquote>
  1977. <ul class="simple">
  1978. <li>Writable Lvalue Iterator if <tt class="docutils literal"><span class="pre">transform_iterator::reference</span></tt> is a non-const reference.</li>
  1979. <li>Readable Lvalue Iterator if <tt class="docutils literal"><span class="pre">transform_iterator::reference</span></tt> is a const reference.</li>
  1980. <li>Readable Iterator otherwise.</li>
  1981. </ul>
  1982. </blockquote>
  1983. <p>The <tt class="docutils literal"><span class="pre">transform_iterator</span></tt> models the most refined standard traversal
  1984. concept that is modeled by the <tt class="docutils literal"><span class="pre">Iterator</span></tt> argument.</p>
  1985. <p>If <tt class="docutils literal"><span class="pre">transform_iterator</span></tt> is a model of Readable Lvalue Iterator then
  1986. it models the following original iterator concepts depending on what
  1987. the <tt class="docutils literal"><span class="pre">Iterator</span></tt> argument models.</p>
  1988. <table border="1" class="docutils">
  1989. <colgroup>
  1990. <col width="47%" />
  1991. <col width="53%" />
  1992. </colgroup>
  1993. <thead valign="bottom">
  1994. <tr><th class="head">If <tt class="docutils literal"><span class="pre">Iterator</span></tt> models</th>
  1995. <th class="head">then <tt class="docutils literal"><span class="pre">transform_iterator</span></tt> models</th>
  1996. </tr>
  1997. </thead>
  1998. <tbody valign="top">
  1999. <tr><td>Single Pass Iterator</td>
  2000. <td>Input Iterator</td>
  2001. </tr>
  2002. <tr><td>Forward Traversal Iterator</td>
  2003. <td>Forward Iterator</td>
  2004. </tr>
  2005. <tr><td>Bidirectional Traversal Iterator</td>
  2006. <td>Bidirectional Iterator</td>
  2007. </tr>
  2008. <tr><td>Random Access Traversal Iterator</td>
  2009. <td>Random Access Iterator</td>
  2010. </tr>
  2011. </tbody>
  2012. </table>
  2013. <p>If <tt class="docutils literal"><span class="pre">transform_iterator</span></tt> models Writable Lvalue Iterator then it is a
  2014. mutable iterator (as defined in the old iterator requirements).</p>
  2015. <p><tt class="docutils literal"><span class="pre">transform_iterator&lt;F1,</span> <span class="pre">X,</span> <span class="pre">R1,</span> <span class="pre">V1&gt;</span></tt> is interoperable with
  2016. <tt class="docutils literal"><span class="pre">transform_iterator&lt;F2,</span> <span class="pre">Y,</span> <span class="pre">R2,</span> <span class="pre">V2&gt;</span></tt> if and only if <tt class="docutils literal"><span class="pre">X</span></tt> is
  2017. interoperable with <tt class="docutils literal"><span class="pre">Y</span></tt>.</p>
  2018. </div>
  2019. <div class="section" id="transform-iterator-operations">
  2020. <h4><a class="toc-backref" href="#id57"><tt class="docutils literal"><span class="pre">transform_iterator</span></tt> operations</a></h4>
  2021. <p>In addition to the operations required by the concepts modeled by
  2022. <tt class="docutils literal"><span class="pre">transform_iterator</span></tt>, <tt class="docutils literal"><span class="pre">transform_iterator</span></tt> provides the following
  2023. operations.</p>
  2024. <p><tt class="docutils literal"><span class="pre">transform_iterator();</span></tt></p>
  2025. <table class="docutils field-list" frame="void" rules="none">
  2026. <col class="field-name" />
  2027. <col class="field-body" />
  2028. <tbody valign="top">
  2029. <tr class="field"><th class="field-name">Returns:</th><td class="field-body">An instance of <tt class="docutils literal"><span class="pre">transform_iterator</span></tt> with <tt class="docutils literal"><span class="pre">m_f</span></tt>
  2030. and <tt class="docutils literal"><span class="pre">m_iterator</span></tt> default constructed.</td>
  2031. </tr>
  2032. </tbody>
  2033. </table>
  2034. <p><tt class="docutils literal"><span class="pre">transform_iterator(Iterator</span> <span class="pre">const&amp;</span> <span class="pre">x,</span> <span class="pre">UnaryFunction</span> <span class="pre">f);</span></tt></p>
  2035. <table class="docutils field-list" frame="void" rules="none">
  2036. <col class="field-name" />
  2037. <col class="field-body" />
  2038. <tbody valign="top">
  2039. <tr class="field"><th class="field-name">Returns:</th><td class="field-body">An instance of <tt class="docutils literal"><span class="pre">transform_iterator</span></tt> with <tt class="docutils literal"><span class="pre">m_f</span></tt>
  2040. initialized to <tt class="docutils literal"><span class="pre">f</span></tt> and <tt class="docutils literal"><span class="pre">m_iterator</span></tt> initialized to <tt class="docutils literal"><span class="pre">x</span></tt>.</td>
  2041. </tr>
  2042. </tbody>
  2043. </table>
  2044. <pre class="literal-block">
  2045. template&lt;class F2, class I2, class R2, class V2&gt;
  2046. transform_iterator(
  2047. transform_iterator&lt;F2, I2, R2, V2&gt; const&amp; t
  2048. , typename enable_if_convertible&lt;I2, Iterator&gt;::type* = 0 // exposition only
  2049. , typename enable_if_convertible&lt;F2, UnaryFunction&gt;::type* = 0 // exposition only
  2050. );
  2051. </pre>
  2052. <table class="docutils field-list" frame="void" rules="none">
  2053. <col class="field-name" />
  2054. <col class="field-body" />
  2055. <tbody valign="top">
  2056. <tr class="field"><th class="field-name">Returns:</th><td class="field-body">An instance of <tt class="docutils literal"><span class="pre">transform_iterator</span></tt> with <tt class="docutils literal"><span class="pre">m_f</span></tt>
  2057. initialized to <tt class="docutils literal"><span class="pre">t.functor()</span></tt> and <tt class="docutils literal"><span class="pre">m_iterator</span></tt> initialized to
  2058. <tt class="docutils literal"><span class="pre">t.base()</span></tt>.</td>
  2059. </tr>
  2060. <tr class="field"><th class="field-name">Requires:</th><td class="field-body"><tt class="docutils literal"><span class="pre">OtherIterator</span></tt> is implicitly convertible to <tt class="docutils literal"><span class="pre">Iterator</span></tt>.</td>
  2061. </tr>
  2062. </tbody>
  2063. </table>
  2064. <p><tt class="docutils literal"><span class="pre">UnaryFunction</span> <span class="pre">functor()</span> <span class="pre">const;</span></tt></p>
  2065. <table class="docutils field-list" frame="void" rules="none">
  2066. <col class="field-name" />
  2067. <col class="field-body" />
  2068. <tbody valign="top">
  2069. <tr class="field"><th class="field-name">Returns:</th><td class="field-body"><tt class="docutils literal"><span class="pre">m_f</span></tt></td>
  2070. </tr>
  2071. </tbody>
  2072. </table>
  2073. <p><tt class="docutils literal"><span class="pre">Iterator</span> <span class="pre">const&amp;</span> <span class="pre">base()</span> <span class="pre">const;</span></tt></p>
  2074. <table class="docutils field-list" frame="void" rules="none">
  2075. <col class="field-name" />
  2076. <col class="field-body" />
  2077. <tbody valign="top">
  2078. <tr class="field"><th class="field-name">Returns:</th><td class="field-body"><tt class="docutils literal"><span class="pre">m_iterator</span></tt></td>
  2079. </tr>
  2080. </tbody>
  2081. </table>
  2082. <p><tt class="docutils literal"><span class="pre">reference</span> <span class="pre">operator*()</span> <span class="pre">const;</span></tt></p>
  2083. <table class="docutils field-list" frame="void" rules="none">
  2084. <col class="field-name" />
  2085. <col class="field-body" />
  2086. <tbody valign="top">
  2087. <tr class="field"><th class="field-name">Returns:</th><td class="field-body"><tt class="docutils literal"><span class="pre">m_f(*m_iterator)</span></tt></td>
  2088. </tr>
  2089. </tbody>
  2090. </table>
  2091. <p><tt class="docutils literal"><span class="pre">transform_iterator&amp;</span> <span class="pre">operator++();</span></tt></p>
  2092. <table class="docutils field-list" frame="void" rules="none">
  2093. <col class="field-name" />
  2094. <col class="field-body" />
  2095. <tbody valign="top">
  2096. <tr class="field"><th class="field-name">Effects:</th><td class="field-body"><tt class="docutils literal"><span class="pre">++m_iterator</span></tt></td>
  2097. </tr>
  2098. <tr class="field"><th class="field-name">Returns:</th><td class="field-body"><tt class="docutils literal"><span class="pre">*this</span></tt></td>
  2099. </tr>
  2100. </tbody>
  2101. </table>
  2102. <p><tt class="docutils literal"><span class="pre">transform_iterator&amp;</span> <span class="pre">operator--();</span></tt></p>
  2103. <table class="docutils field-list" frame="void" rules="none">
  2104. <col class="field-name" />
  2105. <col class="field-body" />
  2106. <tbody valign="top">
  2107. <tr class="field"><th class="field-name">Effects:</th><td class="field-body"><tt class="docutils literal"><span class="pre">--m_iterator</span></tt></td>
  2108. </tr>
  2109. <tr class="field"><th class="field-name">Returns:</th><td class="field-body"><tt class="docutils literal"><span class="pre">*this</span></tt></td>
  2110. </tr>
  2111. </tbody>
  2112. </table>
  2113. </div>
  2114. </div>
  2115. <div class="section" id="filter-iterator">
  2116. <h3><a class="toc-backref" href="#id58">Filter iterator</a></h3>
  2117. <!-- Copyright David Abrahams 2006. Distributed under the Boost -->
  2118. <!-- Software License, Version 1.0. (See accompanying -->
  2119. <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
  2120. <p>The filter iterator adaptor creates a view of an iterator range in
  2121. which some elements of the range are skipped. A predicate function
  2122. object controls which elements are skipped. When the predicate is
  2123. applied to an element, if it returns <tt class="docutils literal"><span class="pre">true</span></tt> then the element is
  2124. retained and if it returns <tt class="docutils literal"><span class="pre">false</span></tt> then the element is skipped
  2125. over. When skipping over elements, it is necessary for the filter
  2126. adaptor to know when to stop so as to avoid going past the end of the
  2127. underlying range. A filter iterator is therefore constructed with pair
  2128. of iterators indicating the range of elements in the unfiltered
  2129. sequence to be traversed.</p>
  2130. <div class="section" id="class-template-filter-iterator">
  2131. <h4><a class="toc-backref" href="#id59">Class template <tt class="docutils literal"><span class="pre">filter_iterator</span></tt></a></h4>
  2132. <!-- Copyright David Abrahams, Jeremy Siek, and Thomas Witt -->
  2133. <!-- 2004. Use, modification and distribution is subject to the Boost -->
  2134. <!-- Software License, Version 1.0. (See accompanying file -->
  2135. <!-- LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
  2136. <pre class="literal-block">
  2137. template &lt;class Predicate, class Iterator&gt;
  2138. class filter_iterator
  2139. {
  2140. public:
  2141. typedef iterator_traits&lt;Iterator&gt;::value_type value_type;
  2142. typedef iterator_traits&lt;Iterator&gt;::reference reference;
  2143. typedef iterator_traits&lt;Iterator&gt;::pointer pointer;
  2144. typedef iterator_traits&lt;Iterator&gt;::difference_type difference_type;
  2145. typedef /* see below */ iterator_category;
  2146. filter_iterator();
  2147. filter_iterator(Predicate f, Iterator x, Iterator end = Iterator());
  2148. filter_iterator(Iterator x, Iterator end = Iterator());
  2149. template&lt;class OtherIterator&gt;
  2150. filter_iterator(
  2151. filter_iterator&lt;Predicate, OtherIterator&gt; const&amp; t
  2152. , typename enable_if_convertible&lt;OtherIterator, Iterator&gt;::type* = 0 // exposition
  2153. );
  2154. Predicate predicate() const;
  2155. Iterator end() const;
  2156. Iterator const&amp; base() const;
  2157. reference operator*() const;
  2158. filter_iterator&amp; operator++();
  2159. private:
  2160. Predicate m_pred; // exposition only
  2161. Iterator m_iter; // exposition only
  2162. Iterator m_end; // exposition only
  2163. };
  2164. </pre>
  2165. <p>If <tt class="docutils literal"><span class="pre">Iterator</span></tt> models Readable Lvalue Iterator and Bidirectional Traversal
  2166. Iterator then <tt class="docutils literal"><span class="pre">iterator_category</span></tt> is convertible to
  2167. <tt class="docutils literal"><span class="pre">std::bidirectional_iterator_tag</span></tt>.
  2168. Otherwise, if <tt class="docutils literal"><span class="pre">Iterator</span></tt> models Readable Lvalue Iterator and Forward Traversal
  2169. Iterator then <tt class="docutils literal"><span class="pre">iterator_category</span></tt> is convertible to
  2170. <tt class="docutils literal"><span class="pre">std::forward_iterator_tag</span></tt>.
  2171. Otherwise <tt class="docutils literal"><span class="pre">iterator_category</span></tt> is
  2172. convertible to <tt class="docutils literal"><span class="pre">std::input_iterator_tag</span></tt>.</p>
  2173. </div>
  2174. <div class="section" id="filter-iterator-requirements">
  2175. <h4><a class="toc-backref" href="#id60"><tt class="docutils literal"><span class="pre">filter_iterator</span></tt> requirements</a></h4>
  2176. <p>The <tt class="docutils literal"><span class="pre">Iterator</span></tt> argument shall meet the requirements of Readable
  2177. Iterator and Single Pass Iterator or it shall meet the requirements of
  2178. Input Iterator.</p>
  2179. <p>The <tt class="docutils literal"><span class="pre">Predicate</span></tt> argument must be Assignable, Copy Constructible, and
  2180. the expression <tt class="docutils literal"><span class="pre">p(x)</span></tt> must be valid where <tt class="docutils literal"><span class="pre">p</span></tt> is an object of type
  2181. <tt class="docutils literal"><span class="pre">Predicate</span></tt>, <tt class="docutils literal"><span class="pre">x</span></tt> is an object of type
  2182. <tt class="docutils literal"><span class="pre">iterator_traits&lt;Iterator&gt;::value_type</span></tt>, and where the type of
  2183. <tt class="docutils literal"><span class="pre">p(x)</span></tt> must be convertible to <tt class="docutils literal"><span class="pre">bool</span></tt>.</p>
  2184. </div>
  2185. <div class="section" id="filter-iterator-models">
  2186. <h4><a class="toc-backref" href="#id61"><tt class="docutils literal"><span class="pre">filter_iterator</span></tt> models</a></h4>
  2187. <p>The concepts that <tt class="docutils literal"><span class="pre">filter_iterator</span></tt> models are dependent on which
  2188. concepts the <tt class="docutils literal"><span class="pre">Iterator</span></tt> argument models, as specified in the
  2189. following tables.</p>
  2190. <table border="1" class="docutils">
  2191. <colgroup>
  2192. <col width="44%" />
  2193. <col width="56%" />
  2194. </colgroup>
  2195. <thead valign="bottom">
  2196. <tr><th class="head">If <tt class="docutils literal"><span class="pre">Iterator</span></tt> models</th>
  2197. <th class="head">then <tt class="docutils literal"><span class="pre">filter_iterator</span></tt> models</th>
  2198. </tr>
  2199. </thead>
  2200. <tbody valign="top">
  2201. <tr><td>Single Pass Iterator</td>
  2202. <td>Single Pass Iterator</td>
  2203. </tr>
  2204. <tr><td>Forward Traversal Iterator</td>
  2205. <td>Forward Traversal Iterator</td>
  2206. </tr>
  2207. <tr><td>Bidirectional Traversal Iterator</td>
  2208. <td>Bidirectional Traversal Iterator</td>
  2209. </tr>
  2210. </tbody>
  2211. </table>
  2212. <table border="1" class="docutils">
  2213. <colgroup>
  2214. <col width="41%" />
  2215. <col width="59%" />
  2216. </colgroup>
  2217. <thead valign="bottom">
  2218. <tr><th class="head">If <tt class="docutils literal"><span class="pre">Iterator</span></tt> models</th>
  2219. <th class="head">then <tt class="docutils literal"><span class="pre">filter_iterator</span></tt> models</th>
  2220. </tr>
  2221. </thead>
  2222. <tbody valign="top">
  2223. <tr><td>Readable Iterator</td>
  2224. <td>Readable Iterator</td>
  2225. </tr>
  2226. <tr><td>Writable Iterator</td>
  2227. <td>Writable Iterator</td>
  2228. </tr>
  2229. <tr><td>Lvalue Iterator</td>
  2230. <td>Lvalue Iterator</td>
  2231. </tr>
  2232. </tbody>
  2233. </table>
  2234. <table border="1" class="docutils">
  2235. <colgroup>
  2236. <col width="63%" />
  2237. <col width="38%" />
  2238. </colgroup>
  2239. <thead valign="bottom">
  2240. <tr><th class="head">If <tt class="docutils literal"><span class="pre">Iterator</span></tt> models</th>
  2241. <th class="head">then <tt class="docutils literal"><span class="pre">filter_iterator</span></tt> models</th>
  2242. </tr>
  2243. </thead>
  2244. <tbody valign="top">
  2245. <tr><td>Readable Iterator, Single Pass Iterator</td>
  2246. <td>Input Iterator</td>
  2247. </tr>
  2248. <tr><td>Readable Lvalue Iterator, Forward Traversal Iterator</td>
  2249. <td>Forward Iterator</td>
  2250. </tr>
  2251. <tr><td>Writable Lvalue Iterator, Forward Traversal Iterator</td>
  2252. <td>Mutable Forward Iterator</td>
  2253. </tr>
  2254. <tr><td>Writable Lvalue Iterator, Bidirectional Iterator</td>
  2255. <td>Mutable Bidirectional Iterator</td>
  2256. </tr>
  2257. </tbody>
  2258. </table>
  2259. <p><tt class="docutils literal"><span class="pre">filter_iterator&lt;P1,</span> <span class="pre">X&gt;</span></tt> is interoperable with <tt class="docutils literal"><span class="pre">filter_iterator&lt;P2,</span> <span class="pre">Y&gt;</span></tt>
  2260. if and only if <tt class="docutils literal"><span class="pre">X</span></tt> is interoperable with <tt class="docutils literal"><span class="pre">Y</span></tt>.</p>
  2261. </div>
  2262. <div class="section" id="filter-iterator-operations">
  2263. <h4><a class="toc-backref" href="#id62"><tt class="docutils literal"><span class="pre">filter_iterator</span></tt> operations</a></h4>
  2264. <p>In addition to those operations required by the concepts that
  2265. <tt class="docutils literal"><span class="pre">filter_iterator</span></tt> models, <tt class="docutils literal"><span class="pre">filter_iterator</span></tt> provides the following
  2266. operations.</p>
  2267. <p><tt class="docutils literal"><span class="pre">filter_iterator();</span></tt></p>
  2268. <table class="docutils field-list" frame="void" rules="none">
  2269. <col class="field-name" />
  2270. <col class="field-body" />
  2271. <tbody valign="top">
  2272. <tr class="field"><th class="field-name">Requires:</th><td class="field-body"><tt class="docutils literal"><span class="pre">Predicate</span></tt> and <tt class="docutils literal"><span class="pre">Iterator</span></tt> must be Default Constructible.</td>
  2273. </tr>
  2274. <tr class="field"><th class="field-name">Effects:</th><td class="field-body">Constructs a <tt class="docutils literal"><span class="pre">filter_iterator</span></tt> whose``m_pred``, <tt class="docutils literal"><span class="pre">m_iter</span></tt>, and <tt class="docutils literal"><span class="pre">m_end</span></tt>
  2275. members are a default constructed.</td>
  2276. </tr>
  2277. </tbody>
  2278. </table>
  2279. <p><tt class="docutils literal"><span class="pre">filter_iterator(Predicate</span> <span class="pre">f,</span> <span class="pre">Iterator</span> <span class="pre">x,</span> <span class="pre">Iterator</span> <span class="pre">end</span> <span class="pre">=</span> <span class="pre">Iterator());</span></tt></p>
  2280. <table class="docutils field-list" frame="void" rules="none">
  2281. <col class="field-name" />
  2282. <col class="field-body" />
  2283. <tbody valign="top">
  2284. <tr class="field"><th class="field-name">Effects:</th><td class="field-body">Constructs a <tt class="docutils literal"><span class="pre">filter_iterator</span></tt> where <tt class="docutils literal"><span class="pre">m_iter</span></tt> is either
  2285. the first position in the range <tt class="docutils literal"><span class="pre">[x,end)</span></tt> such that <tt class="docutils literal"><span class="pre">f(*m_iter)</span> <span class="pre">==</span> <span class="pre">true</span></tt>
  2286. or else``m_iter == end``. The member <tt class="docutils literal"><span class="pre">m_pred</span></tt> is constructed from
  2287. <tt class="docutils literal"><span class="pre">f</span></tt> and <tt class="docutils literal"><span class="pre">m_end</span></tt> from <tt class="docutils literal"><span class="pre">end</span></tt>.</td>
  2288. </tr>
  2289. </tbody>
  2290. </table>
  2291. <p><tt class="docutils literal"><span class="pre">filter_iterator(Iterator</span> <span class="pre">x,</span> <span class="pre">Iterator</span> <span class="pre">end</span> <span class="pre">=</span> <span class="pre">Iterator());</span></tt></p>
  2292. <table class="docutils field-list" frame="void" rules="none">
  2293. <col class="field-name" />
  2294. <col class="field-body" />
  2295. <tbody valign="top">
  2296. <tr class="field"><th class="field-name">Requires:</th><td class="field-body"><tt class="docutils literal"><span class="pre">Predicate</span></tt> must be Default Constructible and
  2297. <tt class="docutils literal"><span class="pre">Predicate</span></tt> is a class type (not a function pointer).</td>
  2298. </tr>
  2299. <tr class="field"><th class="field-name">Effects:</th><td class="field-body">Constructs a <tt class="docutils literal"><span class="pre">filter_iterator</span></tt> where <tt class="docutils literal"><span class="pre">m_iter</span></tt> is either
  2300. the first position in the range <tt class="docutils literal"><span class="pre">[x,end)</span></tt> such that <tt class="docutils literal"><span class="pre">m_pred(*m_iter)</span> <span class="pre">==</span> <span class="pre">true</span></tt>
  2301. or else``m_iter == end``. The member <tt class="docutils literal"><span class="pre">m_pred</span></tt> is default constructed.</td>
  2302. </tr>
  2303. </tbody>
  2304. </table>
  2305. <pre class="literal-block">
  2306. template &lt;class OtherIterator&gt;
  2307. filter_iterator(
  2308. filter_iterator&lt;Predicate, OtherIterator&gt; const&amp; t
  2309. , typename enable_if_convertible&lt;OtherIterator, Iterator&gt;::type* = 0 // exposition
  2310. );``
  2311. </pre>
  2312. <table class="docutils field-list" frame="void" rules="none">
  2313. <col class="field-name" />
  2314. <col class="field-body" />
  2315. <tbody valign="top">
  2316. <tr class="field"><th class="field-name">Requires:</th><td class="field-body"><tt class="docutils literal"><span class="pre">OtherIterator</span></tt> is implicitly convertible to <tt class="docutils literal"><span class="pre">Iterator</span></tt>.</td>
  2317. </tr>
  2318. <tr class="field"><th class="field-name">Effects:</th><td class="field-body">Constructs a filter iterator whose members are copied from <tt class="docutils literal"><span class="pre">t</span></tt>.</td>
  2319. </tr>
  2320. </tbody>
  2321. </table>
  2322. <p><tt class="docutils literal"><span class="pre">Predicate</span> <span class="pre">predicate()</span> <span class="pre">const;</span></tt></p>
  2323. <table class="docutils field-list" frame="void" rules="none">
  2324. <col class="field-name" />
  2325. <col class="field-body" />
  2326. <tbody valign="top">
  2327. <tr class="field"><th class="field-name">Returns:</th><td class="field-body"><tt class="docutils literal"><span class="pre">m_pred</span></tt></td>
  2328. </tr>
  2329. </tbody>
  2330. </table>
  2331. <p><tt class="docutils literal"><span class="pre">Iterator</span> <span class="pre">end()</span> <span class="pre">const;</span></tt></p>
  2332. <table class="docutils field-list" frame="void" rules="none">
  2333. <col class="field-name" />
  2334. <col class="field-body" />
  2335. <tbody valign="top">
  2336. <tr class="field"><th class="field-name">Returns:</th><td class="field-body"><tt class="docutils literal"><span class="pre">m_end</span></tt></td>
  2337. </tr>
  2338. </tbody>
  2339. </table>
  2340. <p><tt class="docutils literal"><span class="pre">Iterator</span> <span class="pre">const&amp;</span> <span class="pre">base()</span> <span class="pre">const;</span></tt></p>
  2341. <table class="docutils field-list" frame="void" rules="none">
  2342. <col class="field-name" />
  2343. <col class="field-body" />
  2344. <tbody valign="top">
  2345. <tr class="field"><th class="field-name">Returns:</th><td class="field-body"><tt class="docutils literal"><span class="pre">m_iterator</span></tt></td>
  2346. </tr>
  2347. </tbody>
  2348. </table>
  2349. <p><tt class="docutils literal"><span class="pre">reference</span> <span class="pre">operator*()</span> <span class="pre">const;</span></tt></p>
  2350. <table class="docutils field-list" frame="void" rules="none">
  2351. <col class="field-name" />
  2352. <col class="field-body" />
  2353. <tbody valign="top">
  2354. <tr class="field"><th class="field-name">Returns:</th><td class="field-body"><tt class="docutils literal"><span class="pre">*m_iter</span></tt></td>
  2355. </tr>
  2356. </tbody>
  2357. </table>
  2358. <p><tt class="docutils literal"><span class="pre">filter_iterator&amp;</span> <span class="pre">operator++();</span></tt></p>
  2359. <table class="docutils field-list" frame="void" rules="none">
  2360. <col class="field-name" />
  2361. <col class="field-body" />
  2362. <tbody valign="top">
  2363. <tr class="field"><th class="field-name">Effects:</th><td class="field-body">Increments <tt class="docutils literal"><span class="pre">m_iter</span></tt> and then continues to
  2364. increment <tt class="docutils literal"><span class="pre">m_iter</span></tt> until either <tt class="docutils literal"><span class="pre">m_iter</span> <span class="pre">==</span> <span class="pre">m_end</span></tt>
  2365. or <tt class="docutils literal"><span class="pre">m_pred(*m_iter)</span> <span class="pre">==</span> <span class="pre">true</span></tt>.</td>
  2366. </tr>
  2367. <tr class="field"><th class="field-name">Returns:</th><td class="field-body"><tt class="docutils literal"><span class="pre">*this</span></tt></td>
  2368. </tr>
  2369. </tbody>
  2370. </table>
  2371. </div>
  2372. </div>
  2373. <div class="section" id="counting-iterator">
  2374. <h3><a class="toc-backref" href="#id63">Counting iterator</a></h3>
  2375. <!-- Copyright David Abrahams 2006. Distributed under the Boost -->
  2376. <!-- Software License, Version 1.0. (See accompanying -->
  2377. <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
  2378. <p><tt class="docutils literal"><span class="pre">counting_iterator</span></tt> adapts an object by adding an <tt class="docutils literal"><span class="pre">operator*</span></tt> that
  2379. returns the current value of the object. All other iterator operations
  2380. are forwarded to the adapted object.</p>
  2381. <div class="section" id="class-template-counting-iterator">
  2382. <h4><a class="toc-backref" href="#id64">Class template <tt class="docutils literal"><span class="pre">counting_iterator</span></tt></a></h4>
  2383. <!-- Copyright David Abrahams 2006. Distributed under the Boost -->
  2384. <!-- Software License, Version 1.0. (See accompanying -->
  2385. <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
  2386. <pre class="literal-block">
  2387. template &lt;
  2388. class Incrementable
  2389. , class CategoryOrTraversal = use_default
  2390. , class Difference = use_default
  2391. &gt;
  2392. class counting_iterator
  2393. {
  2394. public:
  2395. typedef Incrementable value_type;
  2396. typedef const Incrementable&amp; reference;
  2397. typedef const Incrementable* pointer;
  2398. typedef /* see below */ difference_type;
  2399. typedef /* see below */ iterator_category;
  2400. counting_iterator();
  2401. counting_iterator(counting_iterator const&amp; rhs);
  2402. explicit counting_iterator(Incrementable x);
  2403. Incrementable const&amp; base() const;
  2404. reference operator*() const;
  2405. counting_iterator&amp; operator++();
  2406. counting_iterator&amp; operator--();
  2407. private:
  2408. Incrementable m_inc; // exposition
  2409. };
  2410. </pre>
  2411. <p>If the <tt class="docutils literal"><span class="pre">Difference</span></tt> argument is <tt class="docutils literal"><span class="pre">use_default</span></tt> then
  2412. <tt class="docutils literal"><span class="pre">difference_type</span></tt> is an unspecified signed integral
  2413. type. Otherwise <tt class="docutils literal"><span class="pre">difference_type</span></tt> is <tt class="docutils literal"><span class="pre">Difference</span></tt>.</p>
  2414. <p><tt class="docutils literal"><span class="pre">iterator_category</span></tt> is determined according to the following
  2415. algorithm:</p>
  2416. <pre class="literal-block">
  2417. if (CategoryOrTraversal is not use_default)
  2418. return CategoryOrTraversal
  2419. else if (numeric_limits&lt;Incrementable&gt;::is_specialized)
  2420. return <a class="reference internal" href="#id12"><em>iterator-category</em></a>(
  2421. random_access_traversal_tag, Incrementable, const Incrementable&amp;)
  2422. else
  2423. return <a class="reference internal" href="#id12"><em>iterator-category</em></a>(
  2424. iterator_traversal&lt;Incrementable&gt;::type,
  2425. Incrementable, const Incrementable&amp;)
  2426. </pre>
  2427. <dl class="docutils">
  2428. <dt>[<em>Note:</em> implementers are encouraged to provide an implementation of</dt>
  2429. <dd><tt class="docutils literal"><span class="pre">operator-</span></tt> and a <tt class="docutils literal"><span class="pre">difference_type</span></tt> that avoids overflows in
  2430. the cases where <tt class="docutils literal"><span class="pre">std::numeric_limits&lt;Incrementable&gt;::is_specialized</span></tt>
  2431. is true.]</dd>
  2432. </dl>
  2433. </div>
  2434. <div class="section" id="counting-iterator-requirements">
  2435. <h4><a class="toc-backref" href="#id65"><tt class="docutils literal"><span class="pre">counting_iterator</span></tt> requirements</a></h4>
  2436. <p>The <tt class="docutils literal"><span class="pre">Incrementable</span></tt> argument shall be Copy Constructible and Assignable.</p>
  2437. <p>If <tt class="docutils literal"><span class="pre">iterator_category</span></tt> is convertible to <tt class="docutils literal"><span class="pre">forward_iterator_tag</span></tt>
  2438. or <tt class="docutils literal"><span class="pre">forward_traversal_tag</span></tt>, the following must be well-formed:</p>
  2439. <pre class="literal-block">
  2440. Incrementable i, j;
  2441. ++i; // pre-increment
  2442. i == j; // operator equal
  2443. </pre>
  2444. <p>If <tt class="docutils literal"><span class="pre">iterator_category</span></tt> is convertible to
  2445. <tt class="docutils literal"><span class="pre">bidirectional_iterator_tag</span></tt> or <tt class="docutils literal"><span class="pre">bidirectional_traversal_tag</span></tt>,
  2446. the following expression must also be well-formed:</p>
  2447. <pre class="literal-block">
  2448. --i
  2449. </pre>
  2450. <p>If <tt class="docutils literal"><span class="pre">iterator_category</span></tt> is convertible to
  2451. <tt class="docutils literal"><span class="pre">random_access_iterator_tag</span></tt> or <tt class="docutils literal"><span class="pre">random_access_traversal_tag</span></tt>,
  2452. the following must must also be valid:</p>
  2453. <pre class="literal-block">
  2454. counting_iterator::difference_type n;
  2455. i += n;
  2456. n = i - j;
  2457. i &lt; j;
  2458. </pre>
  2459. </div>
  2460. <div class="section" id="counting-iterator-models">
  2461. <h4><a class="toc-backref" href="#id66"><tt class="docutils literal"><span class="pre">counting_iterator</span></tt> models</a></h4>
  2462. <p>Specializations of <tt class="docutils literal"><span class="pre">counting_iterator</span></tt> model Readable Lvalue
  2463. Iterator. In addition, they model the concepts corresponding to the
  2464. iterator tags to which their <tt class="docutils literal"><span class="pre">iterator_category</span></tt> is convertible.
  2465. Also, if <tt class="docutils literal"><span class="pre">CategoryOrTraversal</span></tt> is not <tt class="docutils literal"><span class="pre">use_default</span></tt> then
  2466. <tt class="docutils literal"><span class="pre">counting_iterator</span></tt> models the concept corresponding to the iterator
  2467. tag <tt class="docutils literal"><span class="pre">CategoryOrTraversal</span></tt>. Otherwise, if
  2468. <tt class="docutils literal"><span class="pre">numeric_limits&lt;Incrementable&gt;::is_specialized</span></tt>, then
  2469. <tt class="docutils literal"><span class="pre">counting_iterator</span></tt> models Random Access Traversal Iterator.
  2470. Otherwise, <tt class="docutils literal"><span class="pre">counting_iterator</span></tt> models the same iterator traversal
  2471. concepts modeled by <tt class="docutils literal"><span class="pre">Incrementable</span></tt>.</p>
  2472. <p><tt class="docutils literal"><span class="pre">counting_iterator&lt;X,C1,D1&gt;</span></tt> is interoperable with
  2473. <tt class="docutils literal"><span class="pre">counting_iterator&lt;Y,C2,D2&gt;</span></tt> if and only if <tt class="docutils literal"><span class="pre">X</span></tt> is
  2474. interoperable with <tt class="docutils literal"><span class="pre">Y</span></tt>.</p>
  2475. </div>
  2476. <div class="section" id="counting-iterator-operations">
  2477. <h4><a class="toc-backref" href="#id67"><tt class="docutils literal"><span class="pre">counting_iterator</span></tt> operations</a></h4>
  2478. <p>In addition to the operations required by the concepts modeled by
  2479. <tt class="docutils literal"><span class="pre">counting_iterator</span></tt>, <tt class="docutils literal"><span class="pre">counting_iterator</span></tt> provides the following
  2480. operations.</p>
  2481. <p><tt class="docutils literal"><span class="pre">counting_iterator();</span></tt></p>
  2482. <table class="docutils field-list" frame="void" rules="none">
  2483. <col class="field-name" />
  2484. <col class="field-body" />
  2485. <tbody valign="top">
  2486. <tr class="field"><th class="field-name">Requires:</th><td class="field-body"><tt class="docutils literal"><span class="pre">Incrementable</span></tt> is Default Constructible.</td>
  2487. </tr>
  2488. <tr class="field"><th class="field-name">Effects:</th><td class="field-body">Default construct the member <tt class="docutils literal"><span class="pre">m_inc</span></tt>.</td>
  2489. </tr>
  2490. </tbody>
  2491. </table>
  2492. <p><tt class="docutils literal"><span class="pre">counting_iterator(counting_iterator</span> <span class="pre">const&amp;</span> <span class="pre">rhs);</span></tt></p>
  2493. <table class="docutils field-list" frame="void" rules="none">
  2494. <col class="field-name" />
  2495. <col class="field-body" />
  2496. <tbody valign="top">
  2497. <tr class="field"><th class="field-name">Effects:</th><td class="field-body">Construct member <tt class="docutils literal"><span class="pre">m_inc</span></tt> from <tt class="docutils literal"><span class="pre">rhs.m_inc</span></tt>.</td>
  2498. </tr>
  2499. </tbody>
  2500. </table>
  2501. <p><tt class="docutils literal"><span class="pre">explicit</span> <span class="pre">counting_iterator(Incrementable</span> <span class="pre">x);</span></tt></p>
  2502. <table class="docutils field-list" frame="void" rules="none">
  2503. <col class="field-name" />
  2504. <col class="field-body" />
  2505. <tbody valign="top">
  2506. <tr class="field"><th class="field-name">Effects:</th><td class="field-body">Construct member <tt class="docutils literal"><span class="pre">m_inc</span></tt> from <tt class="docutils literal"><span class="pre">x</span></tt>.</td>
  2507. </tr>
  2508. </tbody>
  2509. </table>
  2510. <p><tt class="docutils literal"><span class="pre">reference</span> <span class="pre">operator*()</span> <span class="pre">const;</span></tt></p>
  2511. <table class="docutils field-list" frame="void" rules="none">
  2512. <col class="field-name" />
  2513. <col class="field-body" />
  2514. <tbody valign="top">
  2515. <tr class="field"><th class="field-name">Returns:</th><td class="field-body"><tt class="docutils literal"><span class="pre">m_inc</span></tt></td>
  2516. </tr>
  2517. </tbody>
  2518. </table>
  2519. <p><tt class="docutils literal"><span class="pre">counting_iterator&amp;</span> <span class="pre">operator++();</span></tt></p>
  2520. <table class="docutils field-list" frame="void" rules="none">
  2521. <col class="field-name" />
  2522. <col class="field-body" />
  2523. <tbody valign="top">
  2524. <tr class="field"><th class="field-name">Effects:</th><td class="field-body"><tt class="docutils literal"><span class="pre">++m_inc</span></tt></td>
  2525. </tr>
  2526. <tr class="field"><th class="field-name">Returns:</th><td class="field-body"><tt class="docutils literal"><span class="pre">*this</span></tt></td>
  2527. </tr>
  2528. </tbody>
  2529. </table>
  2530. <p><tt class="docutils literal"><span class="pre">counting_iterator&amp;</span> <span class="pre">operator--();</span></tt></p>
  2531. <table class="docutils field-list" frame="void" rules="none">
  2532. <col class="field-name" />
  2533. <col class="field-body" />
  2534. <tbody valign="top">
  2535. <tr class="field"><th class="field-name">Effects:</th><td class="field-body"><tt class="docutils literal"><span class="pre">--m_inc</span></tt></td>
  2536. </tr>
  2537. <tr class="field"><th class="field-name">Returns:</th><td class="field-body"><tt class="docutils literal"><span class="pre">*this</span></tt></td>
  2538. </tr>
  2539. </tbody>
  2540. </table>
  2541. <p><tt class="docutils literal"><span class="pre">Incrementable</span> <span class="pre">const&amp;</span> <span class="pre">base()</span> <span class="pre">const;</span></tt></p>
  2542. <table class="docutils field-list" frame="void" rules="none">
  2543. <col class="field-name" />
  2544. <col class="field-body" />
  2545. <tbody valign="top">
  2546. <tr class="field"><th class="field-name">Returns:</th><td class="field-body"><tt class="docutils literal"><span class="pre">m_inc</span></tt></td>
  2547. </tr>
  2548. </tbody>
  2549. </table>
  2550. </div>
  2551. </div>
  2552. <div class="section" id="function-output-iterator">
  2553. <h3><a class="toc-backref" href="#id68">Function output iterator</a></h3>
  2554. <!-- Copyright David Abrahams 2006. Distributed under the Boost -->
  2555. <!-- Software License, Version 1.0. (See accompanying -->
  2556. <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
  2557. <p>The function output iterator adaptor makes it easier to create custom
  2558. output iterators. The adaptor takes a unary function and creates a
  2559. model of Output Iterator. Each item assigned to the output iterator is
  2560. passed as an argument to the unary function. The motivation for this
  2561. iterator is that creating a conforming output iterator is non-trivial,
  2562. particularly because the proper implementation usually requires a
  2563. proxy object.</p>
  2564. <div class="section" id="class-template-function-output-iterator">
  2565. <h4><a class="toc-backref" href="#id69">Class template <tt class="docutils literal"><span class="pre">function_output_iterator</span></tt></a></h4>
  2566. <!-- Copyright David Abrahams 2006. Distributed under the Boost -->
  2567. <!-- Software License, Version 1.0. (See accompanying -->
  2568. <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
  2569. </div>
  2570. <div class="section" id="header">
  2571. <h4><a class="toc-backref" href="#id70">Header</a></h4>
  2572. <pre class="literal-block">
  2573. #include &lt;boost/function_output_iterator.hpp&gt;
  2574. </pre>
  2575. <pre class="literal-block">
  2576. template &lt;class UnaryFunction&gt;
  2577. class function_output_iterator {
  2578. public:
  2579. typedef std::output_iterator_tag iterator_category;
  2580. typedef void value_type;
  2581. typedef void difference_type;
  2582. typedef void pointer;
  2583. typedef void reference;
  2584. explicit function_output_iterator();
  2585. explicit function_output_iterator(const UnaryFunction&amp; f);
  2586. /* see below */ operator*();
  2587. function_output_iterator&amp; operator++();
  2588. function_output_iterator&amp; operator++(int);
  2589. private:
  2590. UnaryFunction m_f; // exposition only
  2591. };
  2592. </pre>
  2593. </div>
  2594. <div class="section" id="function-output-iterator-requirements">
  2595. <h4><a class="toc-backref" href="#id71"><tt class="docutils literal"><span class="pre">function_output_iterator</span></tt> requirements</a></h4>
  2596. <p><tt class="docutils literal"><span class="pre">UnaryFunction</span></tt> must be Assignable and Copy Constructible.</p>
  2597. </div>
  2598. <div class="section" id="function-output-iterator-models">
  2599. <h4><a class="toc-backref" href="#id72"><tt class="docutils literal"><span class="pre">function_output_iterator</span></tt> models</a></h4>
  2600. <p><tt class="docutils literal"><span class="pre">function_output_iterator</span></tt> is a model of the Writable and
  2601. Incrementable Iterator concepts.</p>
  2602. </div>
  2603. <div class="section" id="function-output-iterator-operations">
  2604. <h4><a class="toc-backref" href="#id73"><tt class="docutils literal"><span class="pre">function_output_iterator</span></tt> operations</a></h4>
  2605. <p><tt class="docutils literal"><span class="pre">explicit</span> <span class="pre">function_output_iterator(const</span> <span class="pre">UnaryFunction&amp;</span> <span class="pre">f</span> <span class="pre">=</span> <span class="pre">UnaryFunction());</span></tt></p>
  2606. <table class="docutils field-list" frame="void" rules="none">
  2607. <col class="field-name" />
  2608. <col class="field-body" />
  2609. <tbody valign="top">
  2610. <tr class="field"><th class="field-name">Effects:</th><td class="field-body">Constructs an instance of <tt class="docutils literal"><span class="pre">function_output_iterator</span></tt>
  2611. with <tt class="docutils literal"><span class="pre">m_f</span></tt> constructed from <tt class="docutils literal"><span class="pre">f</span></tt>.</td>
  2612. </tr>
  2613. </tbody>
  2614. </table>
  2615. <p><tt class="docutils literal"><span class="pre">operator*();</span></tt></p>
  2616. <table class="docutils field-list" frame="void" rules="none">
  2617. <col class="field-name" />
  2618. <col class="field-body" />
  2619. <tbody valign="top">
  2620. <tr class="field"><th class="field-name">Returns:</th><td class="field-body">An object <tt class="docutils literal"><span class="pre">r</span></tt> of unspecified type such that <tt class="docutils literal"><span class="pre">r</span> <span class="pre">=</span> <span class="pre">t</span></tt>
  2621. is equivalent to <tt class="docutils literal"><span class="pre">m_f(t)</span></tt> for all <tt class="docutils literal"><span class="pre">t</span></tt>.</td>
  2622. </tr>
  2623. </tbody>
  2624. </table>
  2625. <p><tt class="docutils literal"><span class="pre">function_output_iterator&amp;</span> <span class="pre">operator++();</span></tt></p>
  2626. <table class="docutils field-list" frame="void" rules="none">
  2627. <col class="field-name" />
  2628. <col class="field-body" />
  2629. <tbody valign="top">
  2630. <tr class="field"><th class="field-name">Returns:</th><td class="field-body"><tt class="docutils literal"><span class="pre">*this</span></tt></td>
  2631. </tr>
  2632. </tbody>
  2633. </table>
  2634. <p><tt class="docutils literal"><span class="pre">function_output_iterator&amp;</span> <span class="pre">operator++(int);</span></tt></p>
  2635. <table class="docutils field-list" frame="void" rules="none">
  2636. <col class="field-name" />
  2637. <col class="field-body" />
  2638. <tbody valign="top">
  2639. <tr class="field"><th class="field-name">Returns:</th><td class="field-body"><tt class="docutils literal"><span class="pre">*this</span></tt></td>
  2640. </tr>
  2641. </tbody>
  2642. </table>
  2643. <!-- LocalWords: Abrahams Siek Witt istream ostream iter MTL strided interoperate
  2644. LocalWords: CRTP metafunctions inlining lvalue JGS incrementable BGL LEDA cv
  2645. LocalWords: GraphBase struct ptrdiff UnaryFunction const int typename bool pp
  2646. LocalWords: lhs rhs SFINAE markup iff tmp OtherDerived OtherIterator DWA foo
  2647. LocalWords: dereferenceable subobject AdaptableUnaryFunction impl pre ifdef'd
  2648. LocalWords: OtherIncrementable Coplien -->
  2649. </div>
  2650. </div>
  2651. </div>
  2652. </div>
  2653. </div>
  2654. <div class="footer">
  2655. <hr class="footer" />
  2656. <a class="reference external" href="facade-and-adaptor.rst">View document source</a>.
  2657. Generated by <a class="reference external" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference external" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source.
  2658. </div>
  2659. </body>
  2660. </html>