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">
5 <meta http-equiv=
"Content-Type" content=
"text/html; charset=utf-8" />
6 <meta name=
"generator" content=
"Docutils 0.3.10: http://docutils.sourceforge.net/" />
7 <title>Boost Pointer Container Library
</title>
8 <style type=
"text/css">
11 :Author: David Goodger
12 :Contact: goodger@users.sourceforge.net
15 :Copyright: This stylesheet has been placed in the public domain.
17 Default cascading style sheet for the HTML output of Docutils.
19 See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
20 customize this style sheet.
23 /*
"! important" is used here to override other ``margin-top`` and
24 ``margin-bottom`` styles that are later in the stylesheet or
25 more specific. See http://www.w3.org/TR/CSS1#the-cascade */
27 margin-top:
0 ! important }
29 .last, .with-subtitle {
30 margin-bottom:
0 ! important }
36 text-decoration: none ;
43 margin-bottom:
0.5em }
45 /* Uncomment (and remove this text!) to get bold-faced definition list terms
53 div.abstract p.topic-title {
57 div.admonition, div.attention, div.caution, div.danger, div.error,
58 div.hint, div.important, div.note, div.tip, div.warning {
60 border: medium outset ;
63 div.admonition p.admonition-title, div.hint p.admonition-title,
64 div.important p.admonition-title, div.note p.admonition-title,
65 div.tip p.admonition-title {
67 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 {
74 font-family: sans-serif }
76 /* Uncomment (and remove this text!) to get reduced vertical space in
78 div.compound .compound-first, div.compound .compound-middle {
79 margin-bottom:
0.5em }
81 div.compound .compound-last, div.compound .compound-middle {
90 div.dedication p.topic-title {
97 div.footer, div.header {
106 div.line-block div.line-block {
113 border: medium outset ;
115 background-color: #ffffee ;
120 div.sidebar p.rubric {
121 font-family: sans-serif ;
124 div.system-messages {
127 div.system-messages h1 {
131 border: medium outset ;
134 div.system-message p.system-message-title {
141 h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
142 h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
163 ol.simple, ul.simple {
167 list-style: decimal }
170 list-style: lower-alpha }
173 list-style: upper-alpha }
176 list-style: lower-roman }
179 list-style: upper-roman }
193 white-space: nowrap }
202 font-family: sans-serif ;
207 font-family: sans-serif ;
223 pre.literal-block, pre.doctest-block {
226 background-color: #eeeeee }
229 font-family: sans-serif ;
230 font-style: oblique }
232 span.classifier-delimiter {
233 font-family: sans-serif ;
237 font-family: sans-serif }
240 white-space: nowrap }
248 span.section-subtitle {
249 /* font-size relative to parent (h1..h6 element) */
253 border-left: solid thin gray }
260 margin-bottom:
0.5em }
263 border-left: solid thin black }
265 table.docutils td, table.docutils th,
266 table.docinfo td, table.docinfo th {
267 padding-left:
0.5em ;
268 padding-right:
0.5em ;
269 vertical-align: top }
271 table.docutils th.field-name, table.docinfo th.docinfo-name {
274 white-space: nowrap ;
277 h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
278 h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
282 background-color: #eeeeee }
285 list-style-type: none }
290 <div class=
"document" id=
"boost-pointer-container-library">
291 <h1 class=
"title"><img alt=
"Boost" src=
"boost.png" /> Pointer Container Library
</h1>
292 <h2 class=
"subtitle" id=
"conventions">Conventions
</h2>
293 <p>There are a few design decisions that will affect how the classes are
294 used. Besides these the classes are much like normal standard containers
295 and provides almost the same interface. The new conventions are:
</p>
296 <div class=
"contents local topic">
298 <li><a class=
"reference" href=
"#null-pointers-are-not-allowed-by-default" id=
"id3" name=
"id3">Null pointers are not allowed by default
</a></li>
299 <li><a class=
"reference" href=
"#all-default-iterators-apply-an-extra-layer-of-indirection" id=
"id4" name=
"id4">All default iterators apply an extra layer of indirection
</a></li>
300 <li><a class=
"reference" href=
"#all-comparison-operations-are-done-on-the-pointed-to-objects-and-not-at-the-pointer-level" id=
"id5" name=
"id5">All comparison operations are done on the pointed to objects and not at the pointer level
</a></li>
301 <li><a class=
"reference" href=
"#stored-elements-are-required-to-be-cloneable-for-a-subset-of-the-operations" id=
"id6" name=
"id6">Stored elements are required to be Cloneable for a subset of the operations
</a></li>
302 <li><a class=
"reference" href=
"#whenever-objects-are-inserted-into-a-container-they-are-cloned-before-insertion" id=
"id7" name=
"id7">Whenever objects are inserted into a container, they are cloned before insertion
</a></li>
303 <li><a class=
"reference" href=
"#whenever-pointers-are-inserted-into-a-container-ownership-is-transferred-to-the-container" id=
"id8" name=
"id8">Whenever pointers are inserted into a container, ownership is transferred to the container
</a></li>
304 <li><a class=
"reference" href=
"#ownership-can-be-transferred-from-a-container-on-a-per-pointer-basis" id=
"id9" name=
"id9">Ownership can be transferred from a container on a per pointer basis
</a></li>
305 <li><a class=
"reference" href=
"#ownership-can-be-transferred-from-a-container-to-another-container-on-a-per-iterator-range-basis" id=
"id10" name=
"id10">Ownership can be transferred from a container to another container on a per iterator range basis
</a></li>
306 <li><a class=
"reference" href=
"#a-container-can-be-cheaply-returned-from-functions-either-by-making-a-clone-or-by-giving-up-ownership-of-the-container" id=
"id11" name=
"id11">A container can be cheaply returned from functions either by making a clone or by giving up ownership of the container
</a></li>
307 <li><a class=
"reference" href=
"#iterators-are-invalidated-as-in-the-corresponding-standard-container" id=
"id12" name=
"id12">Iterators are invalidated as in the corresponding standard container
</a></li>
310 <div class=
"section">
311 <h1><a class=
"toc-backref" href=
"#id3" id=
"null-pointers-are-not-allowed-by-default" name=
"null-pointers-are-not-allowed-by-default">Null pointers are not allowed by default
</a></h1>
312 <p>If the user tries to insert the null pointer, the operation will throw a
313 <tt class=
"docutils literal"><span class=
"pre">bad_pointer
</span></tt> exception (see
<a class=
"reference" href=
"examples.html">Example
1</a>).
</p>
314 <p>Use
<a class=
"reference" href=
"reference.html#class-nullable">nullable
</a> to allow null pointers.
</p>
315 <p>Please notice that all preconditions of the form
</p>
316 <pre class=
"literal-block">
319 <p>are not active when the you have instantiated a container
320 with
<tt class=
"docutils literal"><span class=
"pre">nullable
<T
></span></tt> as in
</p>
321 <pre class=
"literal-block">
322 boost::ptr_vector
< boost::nullable
<animal
> > vec;
323 vec.push_back(
0 ); // ok
326 <div class=
"section">
327 <h1><a class=
"toc-backref" href=
"#id4" id=
"all-default-iterators-apply-an-extra-layer-of-indirection" name=
"all-default-iterators-apply-an-extra-layer-of-indirection">All default iterators apply an extra layer of indirection
</a></h1>
329 make the containers easier and safer to use. It promotes a kind of
330 pointer-less programming and the user of a class needs not worry about
331 pointers except when allocating them (see
<a class=
"reference" href=
"examples.html">Example
2</a>). Iterators that
332 provide access to the naked pointers are also provided since they might be
333 useful in rare cases. For example, whenever
<tt class=
"docutils literal"><span class=
"pre">begin()
</span></tt> returns an iterator,
334 <tt class=
"docutils literal"><span class=
"pre">ptr_begin()
</span></tt> will return an iterator that allows one to iterate over the
337 <div class=
"section">
338 <h1><a class=
"toc-backref" href=
"#id5" id=
"all-comparison-operations-are-done-on-the-pointed-to-objects-and-not-at-the-pointer-level" name=
"all-comparison-operations-are-done-on-the-pointed-to-objects-and-not-at-the-pointer-level">All comparison operations are done on the pointed to objects and not at the pointer level
</a></h1>
339 <p>For example, in
<tt class=
"docutils literal"><span class=
"pre">ptr_set
<T
></span></tt> the ordering is by default done by
340 <tt class=
"docutils literal"><span class=
"pre">boost::ptr_less
<T
></span></tt> which compares the indirected pointers.
341 Similarly,
<tt class=
"docutils literal"><span class=
"pre">operator==()
</span></tt> for
<tt class=
"docutils literal"><span class=
"pre">container
<Foo
></span></tt> compares all objects
342 with
<tt class=
"docutils literal"><span class=
"pre">operator==(const
</span> <span class=
"pre">Foo
&,
</span> <span class=
"pre">const
</span> <span class=
"pre">Foo
&)
</span></tt>.
</p>
344 <div class=
"section">
345 <h1><a id=
"stored-elements-are-required-to-be-cloneable-for-a-subset-of-the-operations" name=
"stored-elements-are-required-to-be-cloneable-for-a-subset-of-the-operations">Stored elements are required to be
<a class=
"reference" href=
"reference.html#the-Cloneable-concept">Cloneable
</a> for a subset of the operations
</a></h1>
346 <p>This is because most polymorphic objects cannot be copied directly, but
347 they can often be so by a use of a member function (see
<a class=
"reference" href=
"examples.html">Example
4</a>). Often
348 it does not even make sense to clone an object in which case a large
349 subset of the operations are still workable.
</p>
351 <div class=
"section">
352 <h1><a class=
"toc-backref" href=
"#id7" id=
"whenever-objects-are-inserted-into-a-container-they-are-cloned-before-insertion" name=
"whenever-objects-are-inserted-into-a-container-they-are-cloned-before-insertion">Whenever objects are inserted into a container, they are cloned before insertion
</a></h1>
353 <p>This is necessary because all pointer containers take ownerships of stored objects
354 (see
<a class=
"reference" href=
"examples.html">Example
5</a>).
</p>
356 <div class=
"section">
357 <h1><a class=
"toc-backref" href=
"#id8" id=
"whenever-pointers-are-inserted-into-a-container-ownership-is-transferred-to-the-container" name=
"whenever-pointers-are-inserted-into-a-container-ownership-is-transferred-to-the-container">Whenever pointers are inserted into a container, ownership is transferred to the container
</a></h1>
358 <p>All containers take ownership of the stored pointers and therefore a
359 container needs to have its own copies (see
<a class=
"reference" href=
"examples.html">Example
5</a>).
</p>
361 <div class=
"section">
362 <h1><a class=
"toc-backref" href=
"#id9" id=
"ownership-can-be-transferred-from-a-container-on-a-per-pointer-basis" name=
"ownership-can-be-transferred-from-a-container-on-a-per-pointer-basis">Ownership can be transferred from a container on a per pointer basis
</a></h1>
363 <p>This can of course also be convenient. Whenever it happens, an
364 <tt class=
"docutils literal"><span class=
"pre">SmartContainer::auto_type
</span></tt> object is used to provide an exception-safe transfer
365 (see
<a class=
"reference" href=
"examples.html">Example
6</a>).
</p>
367 <div class=
"section">
368 <h1><a class=
"toc-backref" href=
"#id10" id=
"ownership-can-be-transferred-from-a-container-to-another-container-on-a-per-iterator-range-basis" name=
"ownership-can-be-transferred-from-a-container-to-another-container-on-a-per-iterator-range-basis">Ownership can be transferred from a container to another container on a per iterator range basis
</a></h1>
369 <p>This makes it possible to exchange data safely between different pointer
370 containers without cloning the objects again (see
<a class=
"reference" href=
"examples.html">Example
7</a>).
</p>
372 <div class=
"section">
373 <h1><a class=
"toc-backref" href=
"#id11" id=
"a-container-can-be-cheaply-returned-from-functions-either-by-making-a-clone-or-by-giving-up-ownership-of-the-container" name=
"a-container-can-be-cheaply-returned-from-functions-either-by-making-a-clone-or-by-giving-up-ownership-of-the-container">A container can be cheaply returned from functions either by making a clone or by giving up ownership of the container
</a></h1>
374 <p>Two special member functions,
<tt class=
"docutils literal"><span class=
"pre">clone()
</span></tt> and
<tt class=
"docutils literal"><span class=
"pre">release()
</span></tt>, both return an
375 <tt class=
"docutils literal"><span class=
"pre">auto_ptr
<SmartContainer
></span></tt> which can be assigned to another pointer container. This
376 effectively reduces the cost of returning a container to one
377 heap-allocation plus a call to
<tt class=
"docutils literal"><span class=
"pre">swap()
</span></tt> (see
<a class=
"reference" href=
"examples.html">Example
3</a>).
</p>
379 <div class=
"section">
380 <h1><a class=
"toc-backref" href=
"#id12" id=
"iterators-are-invalidated-as-in-the-corresponding-standard-container" name=
"iterators-are-invalidated-as-in-the-corresponding-standard-container">Iterators are invalidated as in the corresponding standard container
</a></h1>
381 <p>Because the containers in this library wrap standard containers, the
382 rules for invalidation of iterators are the same as the rules
383 of the corresponding standard container.
</p>
384 <p>For example, for both
<tt class=
"docutils literal"><span class=
"pre">boost::ptr_vector
<T
></span></tt> and
<tt class=
"docutils literal"><span class=
"pre">std::vector
<U
></span></tt>
385 insertion and deletion only invalidates the deleted
386 element and elements following it; all elements before the inserted/deleted
387 element remain valid.
</p>
388 <hr><p><strong>Navigate:
</strong></p>
390 <li><a class=
"reference" href=
"ptr_container.html">home
</a></li>
391 <li><a class=
"reference" href=
"reference.html">reference
</a></li>
393 <hr><table class=
"docutils field-list" frame=
"void" rules=
"none">
394 <col class=
"field-name" />
395 <col class=
"field-body" />
397 <tr class=
"field"><th class=
"field-name">Copyright:
</th><td class=
"field-body">Thorsten Ottosen
2004-
2006. Use, modification and distribution is subject to the Boost Software License, Version
1.0 (see
<a class=
"reference" href=
"http://www.boost.org/LICENSE_1_0.txt">LICENSE_1_0.txt
</a>).
</td>