ptr_vector.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  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. <style type="text/css">
  9. /*
  10. :Author: David Goodger (goodger@python.org)
  11. :Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $
  12. :Copyright: This stylesheet has been placed in the public domain.
  13. Default cascading style sheet for the HTML output of Docutils.
  14. See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
  15. customize this style sheet.
  16. */
  17. /* used to remove borders from tables and images */
  18. .borderless, table.borderless td, table.borderless th {
  19. border: 0 }
  20. table.borderless td, table.borderless th {
  21. /* Override padding for "table.docutils td" with "! important".
  22. The right padding separates the table cells. */
  23. padding: 0 0.5em 0 0 ! important }
  24. .first {
  25. /* Override more specific margin styles with "! important". */
  26. margin-top: 0 ! important }
  27. .last, .with-subtitle {
  28. margin-bottom: 0 ! important }
  29. .hidden {
  30. display: none }
  31. .subscript {
  32. vertical-align: sub;
  33. font-size: smaller }
  34. .superscript {
  35. vertical-align: super;
  36. font-size: smaller }
  37. a.toc-backref {
  38. text-decoration: none ;
  39. color: black }
  40. blockquote.epigraph {
  41. margin: 2em 5em ; }
  42. dl.docutils dd {
  43. margin-bottom: 0.5em }
  44. object[type="image/svg+xml"], object[type="application/x-shockwave-flash"] {
  45. overflow: hidden;
  46. }
  47. /* Uncomment (and remove this text!) to get bold-faced definition list terms
  48. dl.docutils dt {
  49. font-weight: bold }
  50. */
  51. div.abstract {
  52. margin: 2em 5em }
  53. div.abstract p.topic-title {
  54. font-weight: bold ;
  55. text-align: center }
  56. div.admonition, div.attention, div.caution, div.danger, div.error,
  57. div.hint, div.important, div.note, div.tip, div.warning {
  58. margin: 2em ;
  59. border: medium outset ;
  60. padding: 1em }
  61. div.admonition p.admonition-title, div.hint p.admonition-title,
  62. div.important p.admonition-title, div.note p.admonition-title,
  63. div.tip p.admonition-title {
  64. font-weight: bold ;
  65. font-family: sans-serif }
  66. div.attention p.admonition-title, div.caution p.admonition-title,
  67. div.danger p.admonition-title, div.error p.admonition-title,
  68. div.warning p.admonition-title, .code .error {
  69. color: red ;
  70. font-weight: bold ;
  71. font-family: sans-serif }
  72. /* Uncomment (and remove this text!) to get reduced vertical space in
  73. compound paragraphs.
  74. div.compound .compound-first, div.compound .compound-middle {
  75. margin-bottom: 0.5em }
  76. div.compound .compound-last, div.compound .compound-middle {
  77. margin-top: 0.5em }
  78. */
  79. div.dedication {
  80. margin: 2em 5em ;
  81. text-align: center ;
  82. font-style: italic }
  83. div.dedication p.topic-title {
  84. font-weight: bold ;
  85. font-style: normal }
  86. div.figure {
  87. margin-left: 2em ;
  88. margin-right: 2em }
  89. div.footer, div.header {
  90. clear: both;
  91. font-size: smaller }
  92. div.line-block {
  93. display: block ;
  94. margin-top: 1em ;
  95. margin-bottom: 1em }
  96. div.line-block div.line-block {
  97. margin-top: 0 ;
  98. margin-bottom: 0 ;
  99. margin-left: 1.5em }
  100. div.sidebar {
  101. margin: 0 0 0.5em 1em ;
  102. border: medium outset ;
  103. padding: 1em ;
  104. background-color: #ffffee ;
  105. width: 40% ;
  106. float: right ;
  107. clear: right }
  108. div.sidebar p.rubric {
  109. font-family: sans-serif ;
  110. font-size: medium }
  111. div.system-messages {
  112. margin: 5em }
  113. div.system-messages h1 {
  114. color: red }
  115. div.system-message {
  116. border: medium outset ;
  117. padding: 1em }
  118. div.system-message p.system-message-title {
  119. color: red ;
  120. font-weight: bold }
  121. div.topic {
  122. margin: 2em }
  123. h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
  124. h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
  125. margin-top: 0.4em }
  126. h1.title {
  127. text-align: center }
  128. h2.subtitle {
  129. text-align: center }
  130. hr.docutils {
  131. width: 75% }
  132. img.align-left, .figure.align-left, object.align-left, table.align-left {
  133. clear: left ;
  134. float: left ;
  135. margin-right: 1em }
  136. img.align-right, .figure.align-right, object.align-right, table.align-right {
  137. clear: right ;
  138. float: right ;
  139. margin-left: 1em }
  140. img.align-center, .figure.align-center, object.align-center {
  141. display: block;
  142. margin-left: auto;
  143. margin-right: auto;
  144. }
  145. table.align-center {
  146. margin-left: auto;
  147. margin-right: auto;
  148. }
  149. .align-left {
  150. text-align: left }
  151. .align-center {
  152. clear: both ;
  153. text-align: center }
  154. .align-right {
  155. text-align: right }
  156. /* reset inner alignment in figures */
  157. div.align-right {
  158. text-align: inherit }
  159. /* div.align-center * { */
  160. /* text-align: left } */
  161. .align-top {
  162. vertical-align: top }
  163. .align-middle {
  164. vertical-align: middle }
  165. .align-bottom {
  166. vertical-align: bottom }
  167. ol.simple, ul.simple {
  168. margin-bottom: 1em }
  169. ol.arabic {
  170. list-style: decimal }
  171. ol.loweralpha {
  172. list-style: lower-alpha }
  173. ol.upperalpha {
  174. list-style: upper-alpha }
  175. ol.lowerroman {
  176. list-style: lower-roman }
  177. ol.upperroman {
  178. list-style: upper-roman }
  179. p.attribution {
  180. text-align: right ;
  181. margin-left: 50% }
  182. p.caption {
  183. font-style: italic }
  184. p.credits {
  185. font-style: italic ;
  186. font-size: smaller }
  187. p.label {
  188. white-space: nowrap }
  189. p.rubric {
  190. font-weight: bold ;
  191. font-size: larger ;
  192. color: maroon ;
  193. text-align: center }
  194. p.sidebar-title {
  195. font-family: sans-serif ;
  196. font-weight: bold ;
  197. font-size: larger }
  198. p.sidebar-subtitle {
  199. font-family: sans-serif ;
  200. font-weight: bold }
  201. p.topic-title {
  202. font-weight: bold }
  203. pre.address {
  204. margin-bottom: 0 ;
  205. margin-top: 0 ;
  206. font: inherit }
  207. pre.literal-block, pre.doctest-block, pre.math, pre.code {
  208. margin-left: 2em ;
  209. margin-right: 2em }
  210. pre.code .ln { color: grey; } /* line numbers */
  211. pre.code, code { background-color: #eeeeee }
  212. pre.code .comment, code .comment { color: #5C6576 }
  213. pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
  214. pre.code .literal.string, code .literal.string { color: #0C5404 }
  215. pre.code .name.builtin, code .name.builtin { color: #352B84 }
  216. pre.code .deleted, code .deleted { background-color: #DEB0A1}
  217. pre.code .inserted, code .inserted { background-color: #A3D289}
  218. span.classifier {
  219. font-family: sans-serif ;
  220. font-style: oblique }
  221. span.classifier-delimiter {
  222. font-family: sans-serif ;
  223. font-weight: bold }
  224. span.interpreted {
  225. font-family: sans-serif }
  226. span.option {
  227. white-space: nowrap }
  228. span.pre {
  229. white-space: pre }
  230. span.problematic {
  231. color: red }
  232. span.section-subtitle {
  233. /* font-size relative to parent (h1..h6 element) */
  234. font-size: 80% }
  235. table.citation {
  236. border-left: solid 1px gray;
  237. margin-left: 1px }
  238. table.docinfo {
  239. margin: 2em 4em }
  240. table.docutils {
  241. margin-top: 0.5em ;
  242. margin-bottom: 0.5em }
  243. table.footnote {
  244. border-left: solid 1px black;
  245. margin-left: 1px }
  246. table.docutils td, table.docutils th,
  247. table.docinfo td, table.docinfo th {
  248. padding-left: 0.5em ;
  249. padding-right: 0.5em ;
  250. vertical-align: top }
  251. table.docutils th.field-name, table.docinfo th.docinfo-name {
  252. font-weight: bold ;
  253. text-align: left ;
  254. white-space: nowrap ;
  255. padding-left: 0 }
  256. /* "booktabs" style (no vertical lines) */
  257. table.docutils.booktabs {
  258. border: 0px;
  259. border-top: 2px solid;
  260. border-bottom: 2px solid;
  261. border-collapse: collapse;
  262. }
  263. table.docutils.booktabs * {
  264. border: 0px;
  265. }
  266. table.docutils.booktabs th {
  267. border-bottom: thin solid;
  268. text-align: left;
  269. }
  270. h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
  271. h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
  272. font-size: 100% }
  273. ul.auto-toc {
  274. list-style-type: none }
  275. </style>
  276. </head>
  277. <body>
  278. <div class="document" id="boost-pointer-container-library">
  279. <h1 class="title"><img alt="Boost" src="boost.png" /> Pointer Container Library</h1>
  280. <div class="section" id="class-ptr-vector">
  281. <h1>Class <tt class="docutils literal">ptr_vector</tt></h1>
  282. <p>A <tt class="docutils literal">ptr_vector&lt;T&gt;</tt> is a pointer container that uses an underlying <tt class="docutils literal"><span class="pre">std::vector&lt;void*&gt;</span></tt>
  283. to store the pointers.</p>
  284. <p><strong>Hierarchy:</strong></p>
  285. <ul class="simple">
  286. <li><a class="reference external" href="reversible_ptr_container.html">reversible_ptr_container</a><ul>
  287. <li><a class="reference external" href="ptr_sequence_adapter.html">ptr_sequence_adapter</a><ul>
  288. <li><tt class="docutils literal">ptr_vector</tt></li>
  289. <li><a class="reference external" href="ptr_list.html">ptr_list</a></li>
  290. <li><a class="reference external" href="ptr_deque.html">ptr_deque</a></li>
  291. <li><a class="reference external" href="ptr_array.html">ptr_array</a></li>
  292. </ul>
  293. </li>
  294. </ul>
  295. </li>
  296. </ul>
  297. <p><strong>Navigate:</strong></p>
  298. <ul class="simple">
  299. <li><a class="reference external" href="ptr_container.html">home</a></li>
  300. <li><a class="reference external" href="reference.html">reference</a></li>
  301. </ul>
  302. <p><strong>Synopsis:</strong></p>
  303. <pre class="literal-block">
  304. namespace boost
  305. {
  306. template
  307. &lt;
  308. class T,
  309. class CloneAllocator = heap_clone_allocator,
  310. class Allocator = std::allocator&lt;void*&gt;
  311. &gt;
  312. class ptr_vector : public ptr_sequence_adapter
  313. &lt;
  314. T,
  315. std::vector&lt;void*,Allocator&gt;,
  316. CloneAllocator
  317. &gt;
  318. {
  319. public: // <a class="reference internal" href="#construction">construction</a>
  320. explicit ptr_vector( size_type to_reserve );
  321. public: // <a class="reference internal" href="#capacity">capacity</a>
  322. size_type capacity() const;
  323. void reserve( size_type n );
  324. public: // <a class="reference internal" href="#element-access">element access</a>
  325. T&amp; operator[]( size_type n );
  326. const T&amp; operator[]( size_type n ) const;
  327. T&amp; at( size_type n );
  328. const T&amp; at( size_type n ) const;
  329. public: // <a class="reference internal" href="#pointer-container-requirements">pointer container requirements</a>
  330. auto_type replace( size_type idx, T* x );
  331. template&lt; class U &gt;
  332. auto_type replace( size_type idx, <a class="reference external" href="compatible_smart_ptr.html"><em>compatible-smart-ptr</em></a>&lt;U&gt; x );
  333. bool is_null( size_type idx ) const;
  334. public: // <a class="reference internal" href="#c-array-support">C-array support</a>
  335. void transfer( iterator before, T** from, size_type size, bool delete_from = true );
  336. T** c_array();
  337. };
  338. } // namespace 'boost'
  339. </pre>
  340. </div>
  341. <div class="section" id="semantics">
  342. <h1>Semantics</h1>
  343. <div class="section" id="semantics-construction">
  344. <span id="construction"></span><h2>Semantics: construction</h2>
  345. <ul>
  346. <li><p class="first"><tt class="docutils literal">explicit ptr_vector( size_type to_reserve );</tt></p>
  347. <blockquote>
  348. <ul class="simple">
  349. <li>constructs an empty vector with a buffer
  350. of size least <tt class="docutils literal">to_reserve</tt></li>
  351. </ul>
  352. </blockquote>
  353. </li>
  354. </ul>
  355. </div>
  356. <div class="section" id="semantics-capacity">
  357. <span id="capacity"></span><h2>Semantics: capacity</h2>
  358. <ul>
  359. <li><p class="first"><tt class="docutils literal">size_type capacity() const;</tt></p>
  360. <blockquote>
  361. <ul class="simple">
  362. <li>Effects: Returns the size of the allocated buffer</li>
  363. <li>Throws: Nothing</li>
  364. </ul>
  365. </blockquote>
  366. </li>
  367. <li><p class="first"><tt class="docutils literal">void reserve( size_type n );</tt></p>
  368. <blockquote>
  369. <ul class="simple">
  370. <li>Requirements: <tt class="docutils literal">n &lt;= max_size()</tt></li>
  371. <li>Effects: Expands the allocated buffer</li>
  372. <li>Postcondition: <tt class="docutils literal">capacity() &gt;= n</tt></li>
  373. <li>Throws: <tt class="docutils literal"><span class="pre">std::length_error()</span></tt> if <tt class="docutils literal">n &gt; max_size()</tt></li>
  374. </ul>
  375. </blockquote>
  376. </li>
  377. </ul>
  378. </div>
  379. <div class="section" id="semantics-element-access">
  380. <span id="element-access"></span><h2>Semantics: element access</h2>
  381. <ul>
  382. <li><p class="first"><tt class="docutils literal">T&amp; <span class="pre">operator[](</span> size_type n );</tt></p>
  383. </li>
  384. <li><p class="first"><tt class="docutils literal">const T&amp; <span class="pre">operator[](</span> size_type n ) const;</tt></p>
  385. <blockquote>
  386. <ul class="simple">
  387. <li>Requirements: <tt class="docutils literal">n &lt; size()</tt></li>
  388. <li>Effects: Returns a reference to the <tt class="docutils literal">n</tt>'th element</li>
  389. <li>Throws: Nothing</li>
  390. </ul>
  391. </blockquote>
  392. </li>
  393. <li><p class="first"><tt class="docutils literal">T&amp; at( size_type n );</tt></p>
  394. </li>
  395. <li><p class="first"><tt class="docutils literal">const T&amp; at( size_type n ) const;</tt></p>
  396. <blockquote>
  397. <ul class="simple">
  398. <li>Requirements: <tt class="docutils literal">n &lt; size()</tt></li>
  399. <li>Effects: Returns a reference to the <tt class="docutils literal">n</tt>'th element</li>
  400. <li>Throws: <tt class="docutils literal">bad_index</tt> if <tt class="docutils literal">n &gt;= size()</tt></li>
  401. </ul>
  402. </blockquote>
  403. </li>
  404. </ul>
  405. </div>
  406. <div class="section" id="semantics-pointer-container-requirements">
  407. <span id="pointer-container-requirements"></span><h2>Semantics: pointer container requirements</h2>
  408. <ul>
  409. <li><p class="first"><tt class="docutils literal">auto_type replace( size_type idx, T* x );</tt></p>
  410. <blockquote>
  411. <ul class="simple">
  412. <li>Requirements: `` x != 0 and idx &lt; size()``</li>
  413. <li>Effects: returns the object indexed by <tt class="docutils literal">idx</tt> and replaces it with <tt class="docutils literal">x</tt>.</li>
  414. <li>Throws: <tt class="docutils literal">bad_index</tt> if <tt class="docutils literal">idx &gt;= size()</tt> and <tt class="docutils literal">bad_pointer</tt> if <tt class="docutils literal">x == 0</tt>.</li>
  415. <li>Exception safety: Strong guarantee</li>
  416. </ul>
  417. </blockquote>
  418. </li>
  419. <li><p class="first"><tt class="docutils literal">template&lt; class U &gt; auto_type replace( size_type idx, <span class="pre"><a class="reference external" href="compatible_smart_ptr.html"><em>compatible-smart-ptr</em></a>&lt;U&gt;</span> x );</tt></p>
  420. <blockquote>
  421. <ul class="simple">
  422. <li>Effects: <tt class="docutils literal">return replace( idx, x.release() );</tt></li>
  423. </ul>
  424. </blockquote>
  425. </li>
  426. <li><p class="first"><tt class="docutils literal">bool is_null( size_type idx ) const;</tt></p>
  427. <blockquote>
  428. <ul class="simple">
  429. <li>Requirements: <tt class="docutils literal">idx &lt; size()</tt></li>
  430. <li>Effects: returns whether the pointer at index <tt class="docutils literal">idx</tt> is null</li>
  431. <li>Exception safety: Nothrow guarantee</li>
  432. </ul>
  433. </blockquote>
  434. </li>
  435. </ul>
  436. </div>
  437. <div class="section" id="semantics-c-array-support">
  438. <span id="c-array-support"></span><h2>Semantics: C-array support</h2>
  439. <ul>
  440. <li><p class="first"><tt class="docutils literal">void transfer( iterator before, T** from, size_type size, bool delete_from = true );</tt></p>
  441. <blockquote>
  442. <ul class="simple">
  443. <li>Requirements: <tt class="docutils literal">from != 0</tt></li>
  444. <li>Effects: Takes ownership of the dynamic array <tt class="docutils literal">from</tt></li>
  445. <li>Exception safety: Strong guarantee if <tt class="docutils literal">delete_from == true</tt>; if <tt class="docutils literal">delete_from == false</tt>,
  446. and an exception is thrown, the container fails to take ownership.</li>
  447. <li>Remarks: Eventually calls <tt class="docutils literal">delete[] from</tt> if <tt class="docutils literal">delete_from == true</tt>.</li>
  448. </ul>
  449. </blockquote>
  450. </li>
  451. <li><p class="first"><tt class="docutils literal">T** <span class="pre">c_array();</span></tt></p>
  452. <blockquote>
  453. <ul class="simple">
  454. <li>Returns: <tt class="docutils literal">0</tt> if the container is empty; otherwise a pointer to the first element of the stored array</li>
  455. <li>Throws: Nothing</li>
  456. </ul>
  457. </blockquote>
  458. </li>
  459. </ul>
  460. <hr><table class="docutils field-list" frame="void" rules="none">
  461. <col class="field-name" />
  462. <col class="field-body" />
  463. <tbody valign="top">
  464. <tr class="field"><th class="field-name">Copyright:</th><td class="field-body">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>
  465. </tr>
  466. </tbody>
  467. </table>
  468. </div>
  469. </div>
  470. </div>
  471. </body>
  472. </html>