forked from boostorg/smart_ptr
Fix doc errors, add shared_ptr_example program
[SVN r10165]
This commit is contained in:
+7
-23
@@ -192,33 +192,17 @@ stored pointer.</p>
|
||||
<p><code>void swap( shared_ptr<T>& 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<Foo> FooPtr;
|
||||
|
||||
std::vector<FooPtr> foo_vector;
|
||||
std::set<FooPtr> 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. Furthermore, use_count() will be even higher
|
||||
at various times inside the loop, as container operations are performed.
|
||||
<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. Furthermore, use_count() may be even higher
|
||||
at various times while push_back() and insert() container operations are performed.
|
||||
More complicated yet, the container operations may throw exceptions under a
|
||||
variety of circumstances. 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
|
||||
|
||||
Reference in New Issue
Block a user