ptr_container.html 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  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.14: http://docutils.sourceforge.net/" />
  7. <title>Boost Pointer Container Library</title>
  8. <meta name="authors" content="Thorsten Ottosen" />
  9. <meta name="date" content="27th of October 2007" />
  10. <meta name="copyright" content="Thorsten Ottosen 2004-2007. Use, modification and distribution is subject to the Boost Software License, Version 1.0 (see LICENSE_1_0.txt)." />
  11. <style type="text/css">
  12. /*
  13. :Author: David Goodger (goodger@python.org)
  14. :Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $
  15. :Copyright: This stylesheet has been placed in the public domain.
  16. Default cascading style sheet for the HTML output of Docutils.
  17. See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
  18. customize this style sheet.
  19. */
  20. /* used to remove borders from tables and images */
  21. .borderless, table.borderless td, table.borderless th {
  22. border: 0 }
  23. table.borderless td, table.borderless th {
  24. /* Override padding for "table.docutils td" with "! important".
  25. The right padding separates the table cells. */
  26. padding: 0 0.5em 0 0 ! important }
  27. .first {
  28. /* Override more specific margin styles with "! important". */
  29. margin-top: 0 ! important }
  30. .last, .with-subtitle {
  31. margin-bottom: 0 ! important }
  32. .hidden {
  33. display: none }
  34. .subscript {
  35. vertical-align: sub;
  36. font-size: smaller }
  37. .superscript {
  38. vertical-align: super;
  39. font-size: smaller }
  40. a.toc-backref {
  41. text-decoration: none ;
  42. color: black }
  43. blockquote.epigraph {
  44. margin: 2em 5em ; }
  45. dl.docutils dd {
  46. margin-bottom: 0.5em }
  47. object[type="image/svg+xml"], object[type="application/x-shockwave-flash"] {
  48. overflow: hidden;
  49. }
  50. /* Uncomment (and remove this text!) to get bold-faced definition list terms
  51. dl.docutils dt {
  52. font-weight: bold }
  53. */
  54. div.abstract {
  55. margin: 2em 5em }
  56. div.abstract p.topic-title {
  57. font-weight: bold ;
  58. text-align: center }
  59. div.admonition, div.attention, div.caution, div.danger, div.error,
  60. div.hint, div.important, div.note, div.tip, div.warning {
  61. margin: 2em ;
  62. border: medium outset ;
  63. padding: 1em }
  64. div.admonition p.admonition-title, div.hint p.admonition-title,
  65. div.important p.admonition-title, div.note p.admonition-title,
  66. div.tip p.admonition-title {
  67. font-weight: bold ;
  68. font-family: sans-serif }
  69. div.attention p.admonition-title, div.caution p.admonition-title,
  70. div.danger p.admonition-title, div.error p.admonition-title,
  71. div.warning p.admonition-title, .code .error {
  72. color: red ;
  73. font-weight: bold ;
  74. font-family: sans-serif }
  75. /* Uncomment (and remove this text!) to get reduced vertical space in
  76. compound paragraphs.
  77. div.compound .compound-first, div.compound .compound-middle {
  78. margin-bottom: 0.5em }
  79. div.compound .compound-last, div.compound .compound-middle {
  80. margin-top: 0.5em }
  81. */
  82. div.dedication {
  83. margin: 2em 5em ;
  84. text-align: center ;
  85. font-style: italic }
  86. div.dedication p.topic-title {
  87. font-weight: bold ;
  88. font-style: normal }
  89. div.figure {
  90. margin-left: 2em ;
  91. margin-right: 2em }
  92. div.footer, div.header {
  93. clear: both;
  94. font-size: smaller }
  95. div.line-block {
  96. display: block ;
  97. margin-top: 1em ;
  98. margin-bottom: 1em }
  99. div.line-block div.line-block {
  100. margin-top: 0 ;
  101. margin-bottom: 0 ;
  102. margin-left: 1.5em }
  103. div.sidebar {
  104. margin: 0 0 0.5em 1em ;
  105. border: medium outset ;
  106. padding: 1em ;
  107. background-color: #ffffee ;
  108. width: 40% ;
  109. float: right ;
  110. clear: right }
  111. div.sidebar p.rubric {
  112. font-family: sans-serif ;
  113. font-size: medium }
  114. div.system-messages {
  115. margin: 5em }
  116. div.system-messages h1 {
  117. color: red }
  118. div.system-message {
  119. border: medium outset ;
  120. padding: 1em }
  121. div.system-message p.system-message-title {
  122. color: red ;
  123. font-weight: bold }
  124. div.topic {
  125. margin: 2em }
  126. h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
  127. h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
  128. margin-top: 0.4em }
  129. h1.title {
  130. text-align: center }
  131. h2.subtitle {
  132. text-align: center }
  133. hr.docutils {
  134. width: 75% }
  135. img.align-left, .figure.align-left, object.align-left, table.align-left {
  136. clear: left ;
  137. float: left ;
  138. margin-right: 1em }
  139. img.align-right, .figure.align-right, object.align-right, table.align-right {
  140. clear: right ;
  141. float: right ;
  142. margin-left: 1em }
  143. img.align-center, .figure.align-center, object.align-center {
  144. display: block;
  145. margin-left: auto;
  146. margin-right: auto;
  147. }
  148. table.align-center {
  149. margin-left: auto;
  150. margin-right: auto;
  151. }
  152. .align-left {
  153. text-align: left }
  154. .align-center {
  155. clear: both ;
  156. text-align: center }
  157. .align-right {
  158. text-align: right }
  159. /* reset inner alignment in figures */
  160. div.align-right {
  161. text-align: inherit }
  162. /* div.align-center * { */
  163. /* text-align: left } */
  164. .align-top {
  165. vertical-align: top }
  166. .align-middle {
  167. vertical-align: middle }
  168. .align-bottom {
  169. vertical-align: bottom }
  170. ol.simple, ul.simple {
  171. margin-bottom: 1em }
  172. ol.arabic {
  173. list-style: decimal }
  174. ol.loweralpha {
  175. list-style: lower-alpha }
  176. ol.upperalpha {
  177. list-style: upper-alpha }
  178. ol.lowerroman {
  179. list-style: lower-roman }
  180. ol.upperroman {
  181. list-style: upper-roman }
  182. p.attribution {
  183. text-align: right ;
  184. margin-left: 50% }
  185. p.caption {
  186. font-style: italic }
  187. p.credits {
  188. font-style: italic ;
  189. font-size: smaller }
  190. p.label {
  191. white-space: nowrap }
  192. p.rubric {
  193. font-weight: bold ;
  194. font-size: larger ;
  195. color: maroon ;
  196. text-align: center }
  197. p.sidebar-title {
  198. font-family: sans-serif ;
  199. font-weight: bold ;
  200. font-size: larger }
  201. p.sidebar-subtitle {
  202. font-family: sans-serif ;
  203. font-weight: bold }
  204. p.topic-title {
  205. font-weight: bold }
  206. pre.address {
  207. margin-bottom: 0 ;
  208. margin-top: 0 ;
  209. font: inherit }
  210. pre.literal-block, pre.doctest-block, pre.math, pre.code {
  211. margin-left: 2em ;
  212. margin-right: 2em }
  213. pre.code .ln { color: grey; } /* line numbers */
  214. pre.code, code { background-color: #eeeeee }
  215. pre.code .comment, code .comment { color: #5C6576 }
  216. pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
  217. pre.code .literal.string, code .literal.string { color: #0C5404 }
  218. pre.code .name.builtin, code .name.builtin { color: #352B84 }
  219. pre.code .deleted, code .deleted { background-color: #DEB0A1}
  220. pre.code .inserted, code .inserted { background-color: #A3D289}
  221. span.classifier {
  222. font-family: sans-serif ;
  223. font-style: oblique }
  224. span.classifier-delimiter {
  225. font-family: sans-serif ;
  226. font-weight: bold }
  227. span.interpreted {
  228. font-family: sans-serif }
  229. span.option {
  230. white-space: nowrap }
  231. span.pre {
  232. white-space: pre }
  233. span.problematic {
  234. color: red }
  235. span.section-subtitle {
  236. /* font-size relative to parent (h1..h6 element) */
  237. font-size: 80% }
  238. table.citation {
  239. border-left: solid 1px gray;
  240. margin-left: 1px }
  241. table.docinfo {
  242. margin: 2em 4em }
  243. table.docutils {
  244. margin-top: 0.5em ;
  245. margin-bottom: 0.5em }
  246. table.footnote {
  247. border-left: solid 1px black;
  248. margin-left: 1px }
  249. table.docutils td, table.docutils th,
  250. table.docinfo td, table.docinfo th {
  251. padding-left: 0.5em ;
  252. padding-right: 0.5em ;
  253. vertical-align: top }
  254. table.docutils th.field-name, table.docinfo th.docinfo-name {
  255. font-weight: bold ;
  256. text-align: left ;
  257. white-space: nowrap ;
  258. padding-left: 0 }
  259. /* "booktabs" style (no vertical lines) */
  260. table.docutils.booktabs {
  261. border: 0px;
  262. border-top: 2px solid;
  263. border-bottom: 2px solid;
  264. border-collapse: collapse;
  265. }
  266. table.docutils.booktabs * {
  267. border: 0px;
  268. }
  269. table.docutils.booktabs th {
  270. border-bottom: thin solid;
  271. text-align: left;
  272. }
  273. h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
  274. h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
  275. font-size: 100% }
  276. ul.auto-toc {
  277. list-style-type: none }
  278. </style>
  279. </head>
  280. <body>
  281. <div class="document" id="boost-pointer-container-library">
  282. <h1 class="title"><img alt="Boost" src="boost.png" /> Pointer Container Library</h1>
  283. <table class="docinfo" frame="void" rules="none">
  284. <col class="docinfo-name" />
  285. <col class="docinfo-content" />
  286. <tbody valign="top">
  287. <tr><th class="docinfo-name">Authors:</th>
  288. <td>Thorsten Ottosen</td></tr>
  289. <tr><th class="docinfo-name">Contact:</th>
  290. <td><a class="first reference external" href="mailto:nesotto&#64;cs.aau.dk">nesotto&#64;cs.aau.dk</a> or <a class="last reference external" href="mailto:tottosen&#64;dezide.com">tottosen&#64;dezide.com</a></td></tr>
  291. <tr class="organizations field"><th class="docinfo-name">Organizations:</th><td class="field-body"><a class="reference external" href="http://www.cs.aau.dk">Department of Computer Science</a>, Aalborg University, and <a class="reference external" href="http://www.dezide.com">Dezide Aps</a></td>
  292. </tr>
  293. <tr><th class="docinfo-name">Date:</th>
  294. <td>27th of October 2007</td></tr>
  295. <tr><th class="docinfo-name">Copyright:</th>
  296. <td>Thorsten Ottosen 2004-2007. Use, modification and distribution is subject to the Boost Software License, Version 1.0 (see <a class="reference external" href="http://www.boost.org/LICENSE_1_0.txt">LICENSE_1_0.txt</a>).</td></tr>
  297. </tbody>
  298. </table>
  299. <div class="section" id="overview">
  300. <h1>Overview</h1>
  301. <p>Boost.Pointer Container provides containers for holding heap-allocated
  302. objects in an exception-safe manner and with minimal overhead.
  303. The aim of the library is in particular to make OO programming
  304. easier in C++ by establishing a standard set of classes, methods
  305. and designs for dealing with OO specific problems</p>
  306. <ul class="simple">
  307. <li><a class="reference internal" href="#motivation">Motivation</a></li>
  308. <li><a class="reference external" href="tutorial.html">Tutorial</a></li>
  309. <li><a class="reference external" href="reference.html">Reference</a></li>
  310. <li><a class="reference external" href="guidelines.html">Usage guidelines</a></li>
  311. <li><a class="reference external" href="examples.html">Examples</a></li>
  312. <li><a class="reference external" href="headers.html">Library headers</a></li>
  313. <li><a class="reference external" href="faq.html">FAQ</a></li>
  314. <li><a class="reference internal" href="#upgrading-from-boost-v-1-33">Upgrading from Boost v. 1.33.*</a></li>
  315. <li><a class="reference internal" href="#upgrading-from-boost-v-1-34">Upgrading from Boost v. 1.34.*</a></li>
  316. <li><a class="reference internal" href="#upgrading-from-boost-v-1-35">Upgrading from Boost v. 1.35.*</a></li>
  317. <li><a class="reference internal" href="#upgrading-from-boost-v-1-66">Upgrading from Boost v. 1.66.*</a></li>
  318. <li><a class="reference internal" href="#future-developments">Future Developments</a></li>
  319. <li><a class="reference internal" href="#acknowledgements">Acknowledgements</a></li>
  320. <li><a class="reference internal" href="#references">References</a></li>
  321. </ul>
  322. <!-- - `Conventions <conventions.html>`_
  323. - `The Clonable Concept <reference.html#the-clonable-concept>`_
  324. - `The Clone Allocator Concept <reference.html#the-clone-allocator-concept>`_
  325. - `Pointer container adapters <reference.html#pointer-container-adapters>`_
  326. - `Sequence container classes <reference.html#sequence-containers>`_
  327. - `ptr_vector <ptr_vector.html>`_
  328. - `ptr_deque <ptr_deque.html>`_
  329. - `ptr_list <ptr_list.html>`_
  330. - `ptr_array <ptr_array.html>`_
  331. - `Associative container classes <reference.html#associative-containers>`_
  332. - `ptr_set <ptr_set.html>`_
  333. - `ptr_multiset <ptr_multiset.html>`_
  334. - `ptr_map <ptr_map.html>`_
  335. - `ptr_multimap <ptr_multimap.html>`_
  336. - `Indirected functions <indirect_fun.html>`_
  337. - `Class nullable <reference.html#class-nullable>`_
  338. - `Exception classes <reference.html#exception-classes>`_ -->
  339. </div>
  340. <div class="section" id="motivation">
  341. <h1>Motivation</h1>
  342. <p>Whenever a programmer wants to have a container of pointers to
  343. heap-allocated objects, there is usually only one exception-safe way:
  344. to make a container of smart pointers like <a class="reference external" href="../../smart_ptr/shared_ptr.htm">boost::shared_ptr</a>
  345. This approach is suboptimal if</p>
  346. <ol class="arabic simple">
  347. <li>the stored objects are not shared, but owned exclusively, or</li>
  348. </ol>
  349. <!-- -->
  350. <ol class="arabic simple" start="2">
  351. <li>the overhead implied by smart pointers is inappropriate</li>
  352. </ol>
  353. <p>This library therefore provides standard-like containers that are for storing
  354. heap-allocated or <a class="reference external" href="reference.html#the-clonable-concept">cloned</a> objects (or in case of a map, the mapped object must be
  355. a heap-allocated or cloned object). For each of the standard
  356. containers there is a pointer container equivalent that takes ownership of
  357. the objects in an exception safe manner. In this respect the library is intended
  358. to solve the so-called
  359. <a class="reference external" href="faq.html#what-is-the-polymorphic-class-problem">polymorphic class problem</a>.</p>
  360. <p>The advantages of pointer containers are</p>
  361. <ol class="arabic simple">
  362. <li>Exception-safe pointer storage and manipulation.</li>
  363. </ol>
  364. <!-- -->
  365. <ol class="arabic simple" start="2">
  366. <li>Notational convenience compared to the use of containers of pointers.</li>
  367. </ol>
  368. <!-- -->
  369. <ol class="arabic simple" start="3">
  370. <li>Can be used for types that are neither Assignable nor Copy Constructible.</li>
  371. </ol>
  372. <!-- -->
  373. <ol class="arabic simple" start="4">
  374. <li>No memory-overhead as containers of smart pointers can have (see <a class="footnote-reference" href="#id23" id="id2">[11]</a> and <a class="footnote-reference" href="#id25" id="id3">[12]</a>).</li>
  375. </ol>
  376. <!-- -->
  377. <ol class="arabic simple" start="5">
  378. <li>Usually faster than using containers of smart pointers (see <a class="footnote-reference" href="#id23" id="id4">[11]</a> and <a class="footnote-reference" href="#id25" id="id5">[12]</a>).</li>
  379. </ol>
  380. <!-- -->
  381. <ol class="arabic simple" start="6">
  382. <li>The interface is slightly changed towards the domain of pointers
  383. instead of relying on the normal value-based interface. For example,
  384. now it is possible for <tt class="docutils literal">pop_back()</tt> to return the removed element.</li>
  385. </ol>
  386. <!-- -->
  387. <ol class="arabic simple" start="7">
  388. <li>Propagates constness such that one cannot modify the objects via a <tt class="docutils literal">const_iterator</tt>.</li>
  389. </ol>
  390. <!-- -->
  391. <ol class="arabic simple" start="8">
  392. <li>Built-in support for deep-copy semantics via the <a class="reference external" href="reference.html#the-clonable-concept">the Clonable concept</a></li>
  393. </ol>
  394. <p>The disadvantages are</p>
  395. <ol class="arabic simple">
  396. <li>Less flexible than containers of smart pointers like <a class="reference external" href="../../smart_ptr/shared_ptr.htm">boost::shared_ptr</a></li>
  397. </ol>
  398. <p>When you do need shared semantics, this library is not what you need.</p>
  399. </div>
  400. <div class="section" id="upgrading-from-boost-v-1-33">
  401. <h1>Upgrading from Boost v. <tt class="docutils literal">1.33.*</tt></h1>
  402. <p>If you upgrade from one of these versions of Boost, then there has been one
  403. major interface change: map iterators now mimic iterators from <tt class="docutils literal"><span class="pre">std::map</span></tt>.
  404. Previously you may have written</p>
  405. <pre class="literal-block">
  406. for( boost::ptr_map&lt;std::string,T&gt;::iterator i = m.begin(), e = m.end();
  407. i != e; ++i )
  408. {
  409. std::cout &lt;&lt; &quot;key:&quot; &lt;&lt; i.key();
  410. std::cout &lt;&lt; &quot;value:&quot; &lt;&lt; *i;
  411. i-&gt;foo(); // call T::foo()
  412. }
  413. </pre>
  414. <p>and this now needs to be converted into</p>
  415. <pre class="literal-block">
  416. for( boost::ptr_map&lt;std::string,T&gt;::iterator i = m.begin(), e = m.end();
  417. i != e; ++i )
  418. {
  419. std::cout &lt;&lt; &quot;key:&quot; &lt;&lt; i-&gt;first;
  420. std::cout &lt;&lt; &quot;value:&quot; &lt;&lt; *i-&gt;second;
  421. i-&gt;second-&gt;foo(); // call T::foo()
  422. }
  423. </pre>
  424. <p>Apart from the above change, the library now also introduces</p>
  425. <ul>
  426. <li><p class="first"><tt class="docutils literal"><span class="pre">std::auto_ptr&lt;T&gt;</span></tt> overloads:</p>
  427. <pre class="literal-block">
  428. std::auto_ptr&lt;T&gt; p( new T );
  429. container.push_back( p );
  430. </pre>
  431. </li>
  432. <li><p class="first">Derived-to-Base conversion in <tt class="docutils literal">transfer()</tt>:</p>
  433. <pre class="literal-block">
  434. boost::ptr_vector&lt;Base&gt; vec;
  435. boost::ptr_list&lt;Derived&gt; list;
  436. ...
  437. vec.transfer( vec.begin(), list ); // now ok
  438. </pre>
  439. </li>
  440. </ul>
  441. <p>Also note that <a class="reference external" href="../../assign/index.html">Boost.Assign</a> introduces better support
  442. for pointer containers.</p>
  443. </div>
  444. <div class="section" id="upgrading-from-boost-v-1-34">
  445. <h1>Upgrading from Boost v. <tt class="docutils literal">1.34.*</tt></h1>
  446. <p>Serialization has now been made optional thanks to Sebastian Ramacher.
  447. You simply include <tt class="docutils literal">&lt;boost/ptr_container/serialize.hpp&gt;</tt> or perhaps
  448. just one of the more specialized headers.</p>
  449. <p>All containers are now copy-constructible and assignable. So you can e.g. now
  450. do:</p>
  451. <pre class="literal-block">
  452. boost::ptr_vector&lt;Derived&gt; derived = ...;
  453. boost::ptr_vector&lt;Base&gt; base( derived );
  454. base = derived;
  455. </pre>
  456. <p>As the example shows, derived-to-base class conversions are also allowed.</p>
  457. <p>A few general functions have been added:</p>
  458. <pre class="literal-block">
  459. VoidPtrContainer&amp; base();
  460. const VoidPtrContainer&amp; base() const;
  461. </pre>
  462. <p>These allow direct access to the wrapped container which is
  463. sometimes needed when you want to provide extra functionality.</p>
  464. <p>A few new functions have been added to sequences:</p>
  465. <pre class="literal-block">
  466. void resize( size_type size );
  467. void resize( size_type size, T* to_clone );
  468. </pre>
  469. <p><tt class="docutils literal">ptr_vector&lt;T&gt;</tt> has a few new helper functions to integrate better with C-arrays:</p>
  470. <pre class="literal-block">
  471. void transfer( iterator before, T** from, size_type size, bool delete_from = true );
  472. T** c_array();
  473. </pre>
  474. <p>Finally, you can now also &quot;copy&quot; and &quot;assign&quot; an <tt class="docutils literal">auto_type</tt> ptr by calling <tt class="docutils literal">move()</tt>:</p>
  475. <pre class="literal-block">
  476. boost::ptr_vector&lt;T&gt;::auto_type move_ptr = ...;
  477. return boost::ptr_container::move( move_ptr );
  478. </pre>
  479. </div>
  480. <div class="section" id="upgrading-from-boost-v-1-35">
  481. <h1>Upgrading from Boost v. <tt class="docutils literal">1.35.*</tt></h1>
  482. <p>The library has been fairly stable, but a few new containers have been supported:</p>
  483. <ul class="simple">
  484. <li><tt class="docutils literal"><span class="pre">boost::ptr_unordered_set&lt;T&gt;</span></tt> in <tt class="docutils literal">&lt;boost/ptr_container/ptr_unordered_set.hpp&gt;</tt></li>
  485. <li><tt class="docutils literal"><span class="pre">boost::ptr_unordered_map&lt;Key,T&gt;</span></tt> in <tt class="docutils literal">&lt;boost/ptr_container/ptr_unordered_map.hpp&gt;</tt></li>
  486. <li><tt class="docutils literal"><span class="pre">boost::ptr_circular_buffer&lt;T&gt;</span></tt> in <tt class="docutils literal">&lt;boost/ptr_container/ptr_circular_buffer.hpp&gt;</tt></li>
  487. </ul>
  488. <p>There are no docs for these classes yet, but they are almost identical to
  489. <tt class="docutils literal"><span class="pre">boost::ptr_set&lt;T&gt;</span></tt>, <tt class="docutils literal"><span class="pre">boost::ptr_map&lt;Key,T&gt;</span></tt> and <tt class="docutils literal"><span class="pre">boost::ptr_array&lt;T,N&gt;</span></tt>, respectively.
  490. The underlying containers stem from the two boost libraries</p>
  491. <ul class="simple">
  492. <li><a class="reference external" href="../../unordered/index.html">Boost.Unordered</a></li>
  493. <li><a class="reference external" href="../../circular_buffer/index.html">Boost.Circular Buffer</a></li>
  494. </ul>
  495. <p>Furthermore, <a class="reference external" href="ptr_inserter.html">insert iterators</a> have been added.</p>
  496. </div>
  497. <div class="section" id="upgrading-from-boost-v-1-66">
  498. <h1>Upgrading from Boost v. <tt class="docutils literal">1.66.*</tt></h1>
  499. <p>Starting with Boost v. <tt class="docutils literal">1.67.0</tt>, Boost.Pointer Container will use
  500. <a class="reference external" href="../../config/index.html">Boost.Config</a> to conditionally provide
  501. <tt class="docutils literal"><span class="pre">std::unique_ptr</span></tt>-based interfaces in addition to, or instead of,
  502. interfaces using <tt class="docutils literal"><span class="pre">std::auto_ptr</span></tt>. Details
  503. are on the <a class="reference external" href="compatible_smart_ptr.html">Compatible Smart Pointer</a>
  504. page, which also explains the convention in this documentation of using</p>
  505. <pre class="literal-block">
  506. <em>compatible-smart-ptr</em>&lt;T&gt;
  507. </pre>
  508. <p>to indicate such conditional interfaces.</p>
  509. <p>For C++98/03 users, this change has no observable effect.</p>
  510. <p>For C++11/14 users, there is no effect on existing code that used
  511. previous versions of Boost.Pointer Container, but now all function
  512. overloads taking an <tt class="docutils literal"><span class="pre">std::auto_ptr</span></tt> parameter are accompanied by an
  513. overload taking <tt class="docutils literal"><span class="pre">std::unique_ptr</span></tt>. In the case of return types,
  514. <tt class="docutils literal"><span class="pre">std::auto_ptr</span></tt> is still always used. Note however that until C++17,
  515. it is possible to construct <tt class="docutils literal"><span class="pre">std::unique_ptr&lt;T&gt;</span></tt> implicitly from
  516. <tt class="docutils literal"><span class="pre">std::auto_ptr&lt;T&gt;</span></tt>. Thus, users are free to modernize their code by
  517. replacing any explicit mention of <tt class="docutils literal"><span class="pre">std::auto_ptr</span></tt> with
  518. <tt class="docutils literal"><span class="pre">std::unique_ptr</span></tt>. This change falls just short of a
  519. search-and-replace conversion, as it is possible that some code may
  520. have relied on <tt class="docutils literal"><span class="pre">std::auto_ptr</span></tt> being copyable. But such situations
  521. will result in compile-time errors which should be easy to fix.</p>
  522. <p>Although <tt class="docutils literal"><span class="pre">std::auto_ptr</span></tt> is formally removed as of ISO C++17,
  523. certain compiler or standard library vendors have chosen to leave it
  524. in for backwards compatibility. For compilers and standard libraries
  525. where this is <em>not</em> the case, C++17 compilation of code using
  526. Boost.Pointer Container is not possible with Boost v. <tt class="docutils literal">1.66.*</tt> or
  527. earlier. This situation is fixed as of Boost v. <tt class="docutils literal">1.67.0</tt>.</p>
  528. </div>
  529. <div class="section" id="future-developments">
  530. <h1>Future Developments</h1>
  531. <p>There are indications that the <tt class="docutils literal">void*</tt> implementation has a slight
  532. performance overhead compared to a <tt class="docutils literal">T*</tt> based implementation. Furthermore, a
  533. <tt class="docutils literal">T*</tt> based implementation is so much easier to use type-safely
  534. with algorithms. Therefore I anticipate to move to a <tt class="docutils literal">T*</tt> based implementation.</p>
  535. <p>Furthermore, the clone allocator might be allowed to have state.
  536. This design requires some thought, so if you have good ideas and use-cases'
  537. for this, please don't hesitate to contact me.</p>
  538. <p>Also, support for Boost.Interprocess is on the todo list.</p>
  539. <p>There has been a few request for <tt class="docutils literal"><span class="pre">boost::ptr_multi_index_container&lt;T,...&gt;</span></tt>.
  540. I investigated how difficult it would be, and it did turn out to be difficult, albeit
  541. not impossible. But I don't have the resources to implement this beast
  542. for years to come, so if someone really needs this container, I suggest that they
  543. talk with me in private about how it can be done.</p>
  544. </div>
  545. <div class="section" id="acknowledgements">
  546. <h1>Acknowledgements</h1>
  547. <p>The following people have been very helpful:</p>
  548. <ul class="simple">
  549. <li>Bjørn D. Rasmussen for unintentionally motivating me to start this library</li>
  550. <li>Pavel Vozenilek for asking me to make the adapters</li>
  551. <li>David Abrahams for the <tt class="docutils literal">indirect_fun</tt> design</li>
  552. <li>Pavol Droba for being review manager</li>
  553. <li>Ross Boylan for trying out a prototype for real</li>
  554. <li>Felipe Magno de Almeida for giving fedback based on using the
  555. library in production code even before the library was part of boost</li>
  556. <li>Jonathan Turkanis for supplying his <tt class="docutils literal">move_ptr</tt> framework
  557. which is used internally</li>
  558. <li>Stefan Slapeta and Howard Hinnant for Metrowerks support</li>
  559. <li>Russell Hind for help with Borland compatibility</li>
  560. <li>Jonathan Wakely for his great help with GCC compatibility and bug fixes</li>
  561. <li>Pavel Chikulaev for comments and bug-fixes</li>
  562. <li>Andreas Hommel for fixing the nasty Metrowerks bug</li>
  563. <li>Charles Brockman for his many comments on the documentation</li>
  564. <li>Sebastian Ramacher for implementing the optional serialization support</li>
  565. </ul>
  566. </div>
  567. <div class="section" id="references">
  568. <h1>References</h1>
  569. <table class="docutils footnote" frame="void" id="id8" rules="none">
  570. <colgroup><col class="label" /><col /></colgroup>
  571. <tbody valign="top">
  572. <tr><td class="label">[1]</td><td>Matt Austern: <a class="reference external" href="http://www.cuj.com/documents/s=7990/cujcexp1910austern/">&quot;The Standard Librarian: Containers of Pointers&quot;</a> , C/C++ Users Journal Experts Forum.</td></tr>
  573. </tbody>
  574. </table>
  575. <table class="docutils footnote" frame="void" id="id10" rules="none">
  576. <colgroup><col class="label" /><col /></colgroup>
  577. <tbody valign="top">
  578. <tr><td class="label">[2]</td><td>Bjarne Stroustrup, &quot;The C++ Programming Language&quot;, <a class="reference external" href="http://www.research.att.com/~bs/3rd_safe.pdf">Appendix E: &quot;Standard-Library Exception Safety&quot;</a></td></tr>
  579. </tbody>
  580. </table>
  581. <table class="docutils footnote" frame="void" id="id12" rules="none">
  582. <colgroup><col class="label" /><col /></colgroup>
  583. <tbody valign="top">
  584. <tr><td class="label">[3]</td><td>Herb Sutter, &quot;Exceptional C++&quot;.</td></tr>
  585. </tbody>
  586. </table>
  587. <table class="docutils footnote" frame="void" id="id13" rules="none">
  588. <colgroup><col class="label" /><col /></colgroup>
  589. <tbody valign="top">
  590. <tr><td class="label">[4]</td><td>Herb Sutter, &quot;More Exceptional C++&quot;.</td></tr>
  591. </tbody>
  592. </table>
  593. <table class="docutils footnote" frame="void" id="id14" rules="none">
  594. <colgroup><col class="label" /><col /></colgroup>
  595. <tbody valign="top">
  596. <tr><td class="label">[5]</td><td>Kevlin Henney: <a class="reference external" href="http://www.cuj.com/documents/s=7986/cujcexp2002henney/henney.htm">&quot;From Mechanism to Method: The Safe Stacking of Cats&quot;</a> , C++ Experts Forum, February 2002.</td></tr>
  597. </tbody>
  598. </table>
  599. <table class="docutils footnote" frame="void" id="id16" rules="none">
  600. <colgroup><col class="label" /><col /></colgroup>
  601. <tbody valign="top">
  602. <tr><td class="label">[6]</td><td>Some of the few earlier attempts of pointer containers I have seen are the rather interesting <a class="reference external" href="http://www.ntllib.org/asp.html">NTL</a> and the
  603. <a class="reference external" href="http://ootips.org/yonat/4dev/pointainer.h">pointainer</a>.
  604. As of this writing both libraries are not exceptions-safe and can leak.</td></tr>
  605. </tbody>
  606. </table>
  607. <table class="docutils footnote" frame="void" id="id17" rules="none">
  608. <colgroup><col class="label" /><col /></colgroup>
  609. <tbody valign="top">
  610. <tr><td class="label">[7]</td><td>INTERNATIONAL STANDARD, Programming languages --- C++, ISO/IEC 14882, 1998. See section 23 in particular.</td></tr>
  611. </tbody>
  612. </table>
  613. <table class="docutils footnote" frame="void" id="id18" rules="none">
  614. <colgroup><col class="label" /><col /></colgroup>
  615. <tbody valign="top">
  616. <tr><td class="label">[8]</td><td>C++ Standard Library Closed Issues List (Revision 27),
  617. Item 218, <a class="reference external" href="http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-closed.html#218">Algorithms do not use binary predicate objects for default comparisons</a>.</td></tr>
  618. </tbody>
  619. </table>
  620. <table class="docutils footnote" frame="void" id="id20" rules="none">
  621. <colgroup><col class="label" /><col /></colgroup>
  622. <tbody valign="top">
  623. <tr><td class="label">[9]</td><td>C++ Standard Library Active Issues List (Revision 27),
  624. Item 226, <a class="reference external" href="http://gcc.gnu.org/onlinedocs/libstdc++/ext/lwg-active.html#226">User supplied specializations or overloads of namespace std function templates</a>.</td></tr>
  625. </tbody>
  626. </table>
  627. <table class="docutils footnote" frame="void" id="id22" rules="none">
  628. <colgroup><col class="label" /><col /></colgroup>
  629. <tbody valign="top">
  630. <tr><td class="label">[10]</td><td>Harald Nowak, &quot;A remove_if for vector&quot;, C/C++ Users Journal, July 2001.</td></tr>
  631. </tbody>
  632. </table>
  633. <table class="docutils footnote" frame="void" id="id23" rules="none">
  634. <colgroup><col class="label" /><col /></colgroup>
  635. <tbody valign="top">
  636. <tr><td class="label">[11]</td><td><em>(<a class="fn-backref" href="#id2">1</a>, <a class="fn-backref" href="#id4">2</a>)</em> Boost smart pointer <a class="reference external" href="http://www.boost.org/libs/smart_ptr/smarttests.htm">timings</a></td></tr>
  637. </tbody>
  638. </table>
  639. <table class="docutils footnote" frame="void" id="id25" rules="none">
  640. <colgroup><col class="label" /><col /></colgroup>
  641. <tbody valign="top">
  642. <tr><td class="label">[12]</td><td><em>(<a class="fn-backref" href="#id3">1</a>, <a class="fn-backref" href="#id5">2</a>)</em> <a class="reference external" href="http://www.ntllib.org/asp.html">NTL</a>: Array vs std::vector and boost::shared_ptr</td></tr>
  643. </tbody>
  644. </table>
  645. <table class="docutils footnote" frame="void" id="id26" rules="none">
  646. <colgroup><col class="label" /><col /></colgroup>
  647. <tbody valign="top">
  648. <tr><td class="label">[13]</td><td>Kevlin Henney, <a class="reference external" href="http://www.two-sdg.demon.co.uk/curbralan/papers/europlop/NullObject.pdf">Null Object</a>, 2002.</td></tr>
  649. </tbody>
  650. </table>
  651. <hr><table class="docutils field-list" frame="void" rules="none">
  652. <col class="field-name" />
  653. <col class="field-body" />
  654. <tbody valign="top">
  655. <tr class="field"><th class="field-name">Copyright:</th><td class="field-body">Thorsten Ottosen 2004-2006.</td>
  656. </tr>
  657. </tbody>
  658. </table>
  659. </div>
  660. </div>
  661. </body>
  662. </html>