diff --git a/shared_ptr.htm b/shared_ptr.htm index 3fdca13..0d489ad 100644 --- a/shared_ptr.htm +++ b/shared_ptr.htm @@ -192,7 +192,31 @@ stored pointer.
void swap( shared_ptr<T>& other ) throw()
Swaps the two smart pointers, as if by std::swap.
[To be supplied. In the meantime, see smart_ptr_test.cpp.]
+// 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 ); +}+
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. +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.
Revised December 8, 1999
© Copyright Greg Colvin and Beman Dawes 1999. Permission to copy, use,