Fix doc errors, add shared_ptr_example program

[SVN r10165]
This commit is contained in:
Beman Dawes
2001-05-21 14:58:07 +00:00
parent 8f23f07740
commit ac8d0f5505
3 changed files with 105 additions and 25 deletions
+7 -23
View File
@@ -192,33 +192,17 @@ stored pointer.</p>
<p><code>void swap( shared_ptr&lt;T&gt;&amp; other ) throw()</code></p>
<p>Swaps the two smart pointers, as if by std::swap.</p>
<h2>Class <a name="shared_ptr_example">shared_ptr example</a></h2>
<pre>// The application will produce a series of
// objects of type Foo which later must be
// accessed both by occurrence (std::vector)
// and by ordering relationship (std::set).
class Foo { ... };
typedef boost::shared_ptr&lt;Foo&gt; FooPtr;
std::vector&lt;FooPtr&gt; foo_vector;
std::set&lt;FooPtr&gt; foo_set; // NOT multiset!
...
{ // creation loop
FooPtr foo_ptr ( new Foo( ... ) );
foo_vector.push_back( foo_ptr );
foo_set.insert( foo_ptr );
}</pre>
<p>Note that at the termination of the creation loop, some of the FooPtr objects
may have use_count()==1 rather than use_count()==2, since foo_set is a std::set
rather than a std::multiset.&nbsp; Furthermore, use_count() will be even higher
at various times inside the loop, as container operations are performed.&nbsp;
<p>See <a href="shared_ptr_example.cpp"> shared_ptr_example.cpp</a> for a complete example program.</p>
<p>This program builds a std::vector and std::set of FooPtr's.</p>
<p>Note that after the two containers have been populated, some of the FooPtr objects
will have use_count()==1 rather than use_count()==2, since foo_set is a std::set
rather than a std::multiset.&nbsp; Furthermore, use_count() may be even higher
at various times while push_back() and insert() container operations are performed.&nbsp;
More complicated yet, the container operations may throw exceptions under a
variety of circumstances.&nbsp; Without using a smart pointer, memory and
exception management would be a nightmare.</p>
<hr>
<p>Revised <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->10 February, 2001<!--webbot bot="Timestamp" endspan i-checksum="40395" -->
<p>Revised <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->21 May, 2001<!--webbot bot="Timestamp" endspan i-checksum="13958" -->
</p>
<p>© Copyright Greg Colvin and Beman Dawes 1999. Permission to copy, use,
modify, sell and distribute this document is granted provided this copyright