-
diff --git a/boost/smart_ptr/detail/shared_count.hpp b/boost/smart_ptr/detail/shared_count.hpp
index f96a220..214e35e 100644
|
a
|
b
|
public:
|
| 357 | 357 | return pi_ != 0? pi_->use_count(): 0; |
| 358 | 358 | } |
| 359 | 359 | |
| | 360 | long weak_use_count() const // nothrow |
| | 361 | { |
| | 362 | return pi_ != 0 ? pi_->weak_use_count() : 0; |
| | 363 | } |
| | 364 | |
| 360 | 365 | bool unique() const // nothrow |
| 361 | 366 | { |
| 362 | 367 | return use_count() == 1; |
| … |
… |
public:
|
| 483 | 488 | return pi_ != 0? pi_->use_count(): 0; |
| 484 | 489 | } |
| 485 | 490 | |
| | 491 | long weak_use_count() const // nothrow |
| | 492 | { |
| | 493 | return pi_ != 0 ? pi_->weak_use_count() : 0; |
| | 494 | } |
| | 495 | |
| 486 | 496 | bool empty() const // nothrow |
| 487 | 497 | { |
| 488 | 498 | return pi_ == 0; |
-
diff --git a/boost/smart_ptr/detail/sp_counted_base_acc_ia64.hpp b/boost/smart_ptr/detail/sp_counted_base_acc_ia64.hpp
index dffd995..82bdd47 100644
|
a
|
b
|
public:
|
| 141 | 141 | { |
| 142 | 142 | return static_cast<int const volatile &>( use_count_ ); // TODO use ld.acq here |
| 143 | 143 | } |
| | 144 | |
| | 145 | long weak_use_count() const // nothrow |
| | 146 | { |
| | 147 | return static_cast<int const volatile &>( weak_count_ ) - (use_count() != 0); |
| | 148 | } |
| 144 | 149 | }; |
| 145 | 150 | |
| 146 | 151 | } // namespace detail |
-
diff --git a/boost/smart_ptr/detail/sp_counted_base_aix.hpp b/boost/smart_ptr/detail/sp_counted_base_aix.hpp
index 0208678..92278a4 100644
|
a
|
b
|
public:
|
| 133 | 133 | { |
| 134 | 134 | return fetch_and_add( const_cast<int32_t*>(&use_count_), 0 ); |
| 135 | 135 | } |
| | 136 | |
| | 137 | long weak_use_count() const // nothrow |
| | 138 | { |
| | 139 | return fetch_and_add( const_cast<int32_t*>(&weak_count_), 0) - (use_count() != 0); |
| | 140 | } |
| 136 | 141 | }; |
| 137 | 142 | |
| 138 | 143 | } // namespace detail |
-
diff --git a/boost/smart_ptr/detail/sp_counted_base_cw_ppc.hpp b/boost/smart_ptr/detail/sp_counted_base_cw_ppc.hpp
index 51ac56a..0f716e8 100644
|
a
|
b
|
public:
|
| 161 | 161 | { |
| 162 | 162 | return static_cast<long const volatile &>( use_count_ ); |
| 163 | 163 | } |
| | 164 | |
| | 165 | long weak_use_count() const // nothrow |
| | 166 | { |
| | 167 | return static_cast<int const volatile &>( weak_count_ ) - (use_count() != 0); |
| | 168 | } |
| 164 | 169 | }; |
| 165 | 170 | |
| 166 | 171 | } // namespace detail |
-
diff --git a/boost/smart_ptr/detail/sp_counted_base_cw_x86.hpp b/boost/smart_ptr/detail/sp_counted_base_cw_x86.hpp
index 1234e78..29fa288 100644
|
a
|
b
|
public:
|
| 149 | 149 | { |
| 150 | 150 | return static_cast<int const volatile &>( use_count_ ); |
| 151 | 151 | } |
| | 152 | |
| | 153 | long weak_use_count() const // nothrow |
| | 154 | { |
| | 155 | return static_cast<int const volatile &>( weak_count_ ) - (use_count() != 0); |
| | 156 | } |
| 152 | 157 | }; |
| 153 | 158 | |
| 154 | 159 | } // namespace detail |
-
diff --git a/boost/smart_ptr/detail/sp_counted_base_gcc_ia64.hpp b/boost/smart_ptr/detail/sp_counted_base_gcc_ia64.hpp
index d122a49..b3d8a64 100644
|
a
|
b
|
public:
|
| 148 | 148 | { |
| 149 | 149 | return static_cast<int const volatile &>( use_count_ ); // TODO use ld.acq here |
| 150 | 150 | } |
| | 151 | |
| | 152 | long weak_use_count() const // nothrow |
| | 153 | { |
| | 154 | return static_cast<int const volatile &>( weak_count_ ) - (use_count() != 0); |
| | 155 | } |
| 151 | 156 | }; |
| 152 | 157 | |
| 153 | 158 | } // namespace detail |
-
diff --git a/boost/smart_ptr/detail/sp_counted_base_gcc_mips.hpp b/boost/smart_ptr/detail/sp_counted_base_gcc_mips.hpp
index 3f1f449..b72b377 100644
|
a
|
b
|
public:
|
| 172 | 172 | { |
| 173 | 173 | return static_cast<int const volatile &>( use_count_ ); |
| 174 | 174 | } |
| | 175 | |
| | 176 | long weak_use_count() const // nothrow |
| | 177 | { |
| | 178 | return static_cast<int const volatile &>( weak_count_ ) - (use_count() != 0); |
| | 179 | } |
| 175 | 180 | }; |
| 176 | 181 | |
| 177 | 182 | } // namespace detail |
-
diff --git a/boost/smart_ptr/detail/sp_counted_base_gcc_ppc.hpp b/boost/smart_ptr/detail/sp_counted_base_gcc_ppc.hpp
index 7f5c414..f8f1048 100644
|
a
|
b
|
public:
|
| 172 | 172 | { |
| 173 | 173 | return static_cast<int const volatile &>( use_count_ ); |
| 174 | 174 | } |
| | 175 | |
| | 176 | long weak_use_count() const // nothrow |
| | 177 | { |
| | 178 | return static_cast<int const volatile &>( weak_count_ ) - (use_count() != 0); |
| | 179 | } |
| 175 | 180 | }; |
| 176 | 181 | |
| 177 | 182 | } // namespace detail |
-
diff --git a/boost/smart_ptr/detail/sp_counted_base_gcc_sparc.hpp b/boost/smart_ptr/detail/sp_counted_base_gcc_sparc.hpp
index 21fa59d..bd3c128 100644
|
a
|
b
|
public:
|
| 157 | 157 | { |
| 158 | 158 | return const_cast< int32_t const volatile & >( use_count_ ); |
| 159 | 159 | } |
| | 160 | |
| | 161 | long weak_use_count() const // nothrow |
| | 162 | { |
| | 163 | return static_cast< int32_t const volatile & >( weak_count_ ) - (use_count() != 0); |
| | 164 | } |
| 160 | 165 | }; |
| 161 | 166 | |
| 162 | 167 | } // namespace detail |
-
diff --git a/boost/smart_ptr/detail/sp_counted_base_gcc_x86.hpp b/boost/smart_ptr/detail/sp_counted_base_gcc_x86.hpp
index 4d7fa8d..7986747 100644
|
a
|
b
|
public:
|
| 164 | 164 | { |
| 165 | 165 | return static_cast<int const volatile &>( use_count_ ); |
| 166 | 166 | } |
| | 167 | |
| | 168 | long weak_use_count() const // nothrow |
| | 169 | { |
| | 170 | return static_cast<int const volatile &>( weak_count_ ) - (use_count() != 0); |
| | 171 | } |
| 167 | 172 | }; |
| 168 | 173 | |
| 169 | 174 | } // namespace detail |
-
diff --git a/boost/smart_ptr/detail/sp_counted_base_nt.hpp b/boost/smart_ptr/detail/sp_counted_base_nt.hpp
index dfd70e7..cf9951e 100644
|
a
|
b
|
public:
|
| 98 | 98 | { |
| 99 | 99 | return use_count_; |
| 100 | 100 | } |
| | 101 | |
| | 102 | long weak_use_count() const // nothrow |
| | 103 | { |
| | 104 | return weak_count_ - (use_count_ != 0); |
| | 105 | } |
| 101 | 106 | }; |
| 102 | 107 | |
| 103 | 108 | } // namespace detail |
-
diff --git a/boost/smart_ptr/detail/sp_counted_base_pt.hpp b/boost/smart_ptr/detail/sp_counted_base_pt.hpp
index 3c56fec..683f592 100644
|
a
|
b
|
public:
|
| 126 | 126 | |
| 127 | 127 | return r; |
| 128 | 128 | } |
| | 129 | |
| | 130 | long weak_use_count() const // nothrow |
| | 131 | { |
| | 132 | pthread_mutex_lock( &m_ ); |
| | 133 | long r = weak_count_ - (use_count_ != 0); |
| | 134 | pthread_mutex_unlock( &m_ ); |
| | 135 | |
| | 136 | return r; |
| | 137 | } |
| 129 | 138 | }; |
| 130 | 139 | |
| 131 | 140 | } // namespace detail |
-
diff --git a/boost/smart_ptr/detail/sp_counted_base_snc_ps3.hpp b/boost/smart_ptr/detail/sp_counted_base_snc_ps3.hpp
index e51e676..042f6ce 100644
|
a
|
b
|
public:
|
| 152 | 152 | { |
| 153 | 153 | return const_cast< uint32_t const volatile & >( use_count_ ); |
| 154 | 154 | } |
| | 155 | |
| | 156 | long weak_use_count() const // nothrow |
| | 157 | { |
| | 158 | return static_cast< uint32_t const volatile & >( weak_count_ ) - (use_count() != 0); |
| | 159 | } |
| 155 | 160 | }; |
| 156 | 161 | |
| 157 | 162 | } // namespace detail |
-
diff --git a/boost/smart_ptr/detail/sp_counted_base_solaris.hpp b/boost/smart_ptr/detail/sp_counted_base_solaris.hpp
index d1b6bec..fa2b865 100644
|
a
|
b
|
public:
|
| 104 | 104 | { |
| 105 | 105 | return static_cast<long const volatile &>( use_count_ ); |
| 106 | 106 | } |
| | 107 | |
| | 108 | long weak_use_count() const // nothrow |
| | 109 | { |
| | 110 | return static_cast<long const volatile &>( weak_count_ ) - (use_count() != 0); |
| | 111 | } |
| 107 | 112 | }; |
| 108 | 113 | |
| 109 | 114 | } // namespace detail |
-
diff --git a/boost/smart_ptr/detail/sp_counted_base_spin.hpp b/boost/smart_ptr/detail/sp_counted_base_spin.hpp
index bbd11e6..13af5d2 100644
|
a
|
b
|
public:
|
| 122 | 122 | spinlock_pool<1>::scoped_lock lock( &use_count_ ); |
| 123 | 123 | return use_count_; |
| 124 | 124 | } |
| | 125 | |
| | 126 | long weak_use_count() const // nothrow |
| | 127 | { |
| | 128 | spinlock_pool<1>::scoped_lock lock( &use_count_ ); |
| | 129 | return weak_count_ - (use_count_ != 0); |
| | 130 | } |
| 125 | 131 | }; |
| 126 | 132 | |
| 127 | 133 | } // namespace detail |
-
diff --git a/boost/smart_ptr/detail/sp_counted_base_sync.hpp b/boost/smart_ptr/detail/sp_counted_base_sync.hpp
index 41f654e..58cdc9d 100644
|
a
|
b
|
public:
|
| 146 | 146 | { |
| 147 | 147 | return const_cast< sp_int32_t const volatile & >( use_count_ ); |
| 148 | 148 | } |
| | 149 | |
| | 150 | long weak_use_count() const // nothrow |
| | 151 | { |
| | 152 | return static_cast< sp_int32_t const volatile & >( weak_count_ ) - (use_count() != 0); |
| | 153 | } |
| 149 | 154 | }; |
| 150 | 155 | |
| 151 | 156 | } // namespace detail |
-
diff --git a/boost/smart_ptr/detail/sp_counted_base_vacpp_ppc.hpp b/boost/smart_ptr/detail/sp_counted_base_vacpp_ppc.hpp
index 842f58f..b8b65a3 100644
|
a
|
b
|
public:
|
| 141 | 141 | { |
| 142 | 142 | return *const_cast<volatile int*>(&use_count_); |
| 143 | 143 | } |
| | 144 | |
| | 145 | long weak_use_count() const // nothrow |
| | 146 | { |
| | 147 | return *const_cast<volatile int*>(&weak_count_) - (use_count() != 0); |
| | 148 | } |
| 144 | 149 | }; |
| 145 | 150 | |
| 146 | 151 | } // namespace detail |
-
diff --git a/boost/smart_ptr/detail/sp_counted_base_w32.hpp b/boost/smart_ptr/detail/sp_counted_base_w32.hpp
index 06aa456..155e266 100644
|
a
|
b
|
public:
|
| 121 | 121 | { |
| 122 | 122 | return static_cast<long const volatile &>( use_count_ ); |
| 123 | 123 | } |
| | 124 | |
| | 125 | long weak_use_count() const // nothrow |
| | 126 | { |
| | 127 | return static_cast<long const volatile &>( weak_count_ ) - (use_count() != 0); |
| | 128 | } |
| 124 | 129 | }; |
| 125 | 130 | |
| 126 | 131 | } // namespace detail |
-
diff --git a/boost/smart_ptr/shared_ptr.hpp b/boost/smart_ptr/shared_ptr.hpp
index 0932cc3..8af7f9a 100644
|
a
|
b
|
public:
|
| 437 | 437 | return pn.use_count(); |
| 438 | 438 | } |
| 439 | 439 | |
| | 440 | long weak_use_count() const // never throws |
| | 441 | { |
| | 442 | return pn.weak_use_count(); |
| | 443 | } |
| | 444 | |
| 440 | 445 | void swap(shared_ptr<T> & other) // never throws |
| 441 | 446 | { |
| 442 | 447 | std::swap(px, other.px); |
-
diff --git a/boost/smart_ptr/weak_ptr.hpp b/boost/smart_ptr/weak_ptr.hpp
index 5391910..7a24758 100644
|
a
|
b
|
public:
|
| 173 | 173 | return pn.use_count(); |
| 174 | 174 | } |
| 175 | 175 | |
| | 176 | long weak_use_count() const // never throws |
| | 177 | { |
| | 178 | return pn.weak_use_count(); |
| | 179 | } |
| | 180 | |
| 176 | 181 | bool expired() const // never throws |
| 177 | 182 | { |
| 178 | 183 | return pn.use_count() == 0; |
-
diff --git a/libs/smart_ptr/shared_ptr.htm b/libs/smart_ptr/shared_ptr.htm
index 77e1fa8..240d8dc 100644
|
a
|
b
|
void bad()
|
| 136 | 136 | |
| 137 | 137 | bool <A href="#unique" >unique</A>() const; // never throws |
| 138 | 138 | long <A href="#use_count" >use_count</A>() const; // never throws |
| | 139 | long <A href="#weak_use_count" >weak_use_count</A>() const; // never throws |
| 139 | 140 | |
| 140 | 141 | operator <A href="#conversions" ><i>unspecified-bool-type</i></A>() const; // never throws |
| 141 | 142 | |
| … |
… |
q = p;
|
| 384 | 385 | <P><B>Notes:</B> <code>use_count()</code> is not necessarily efficient. Use only |
| 385 | 386 | for debugging and testing purposes, not for production code.</P> |
| 386 | 387 | </blockquote> |
| | 388 | <h3><a name="weak_use_count">weak_use_count</a></h3> |
| | 389 | <pre>long weak_use_count() const; // never throws</pre> |
| | 390 | <blockquote> |
| | 391 | <p><b>Returns:</b> the number of <b>weak_ptr</b> objects that <i>share ownership</i> with <b>*this</b>, |
| | 392 | or 0 when <b>*this</b> is <EM>empty</EM>.</p> |
| | 393 | <p><b>Throws:</b> nothing.</p> |
| | 394 | <P><B>Notes:</B> <code>weak_use_count()</code> is not necessarily efficient. Use only |
| | 395 | for debugging and testing purposes, not for production code.</P> |
| | 396 | </blockquote> |
| 387 | 397 | <h3><a name="conversions">conversions</a></h3> |
| 388 | 398 | <pre>operator <i>unspecified-bool-type</i> () const; // never throws</pre> |
| 389 | 399 | <blockquote> |
| … |
… |
p3.reset(new int(2)); // undefined, multiple writes
|
| 672 | 682 | <P> |
| 673 | 683 | <b>A.</b> Automatic conversion is believed to be too error prone.<BR> |
| 674 | 684 | </P> |
| 675 | | <P><B>Q.</B> Why does <b>shared_ptr</b> supply use_count()?</P> |
| | 685 | <P><B>Q.</B> Why does <b>shared_ptr</b> supply use_count()/weak_use_count()?</P> |
| 676 | 686 | <P> |
| 677 | 687 | <b>A.</b> As an aid to writing test cases and debugging displays. One of the |
| 678 | 688 | progenitors had use_count(), and it was useful in tracking down bugs in a |
-
diff --git a/libs/smart_ptr/test/weak_ptr_test.cpp b/libs/smart_ptr/test/weak_ptr_test.cpp
index a4ad766..819427f 100644
|
a
|
b
|
|
| 29 | 29 | #include <boost/shared_ptr.hpp> |
| 30 | 30 | #include <boost/weak_ptr.hpp> |
| 31 | 31 | |
| | 32 | #include <iostream> |
| 32 | 33 | #include <map> |
| 33 | 34 | #include <vector> |
| 34 | 35 | |
| … |
… |
void default_constructor()
|
| 76 | 77 | { |
| 77 | 78 | boost::weak_ptr<int> wp; |
| 78 | 79 | BOOST_TEST(wp.use_count() == 0); |
| | 80 | BOOST_TEST(wp.weak_use_count() == 0); |
| 79 | 81 | } |
| 80 | 82 | |
| 81 | 83 | { |
| 82 | 84 | boost::weak_ptr<void> wp; |
| 83 | 85 | BOOST_TEST(wp.use_count() == 0); |
| | 86 | BOOST_TEST(wp.weak_use_count() == 0); |
| 84 | 87 | } |
| 85 | 88 | |
| 86 | 89 | { |
| 87 | 90 | boost::weak_ptr<incomplete> wp; |
| 88 | 91 | BOOST_TEST(wp.use_count() == 0); |
| | 92 | BOOST_TEST(wp.weak_use_count() == 0); |
| 89 | 93 | } |
| 90 | 94 | } |
| 91 | 95 | |
| … |
… |
void shared_ptr_constructor()
|
| 96 | 100 | |
| 97 | 101 | boost::weak_ptr<int> wp(sp); |
| 98 | 102 | BOOST_TEST(wp.use_count() == sp.use_count()); |
| | 103 | BOOST_TEST(wp.weak_use_count() == 0); |
| | 104 | BOOST_TEST(wp.weak_use_count() == sp.weak_use_count()); |
| 99 | 105 | |
| 100 | 106 | boost::weak_ptr<void> wp2(sp); |
| 101 | 107 | BOOST_TEST(wp2.use_count() == sp.use_count()); |
| | 108 | BOOST_TEST(wp2.weak_use_count() == 0); |
| | 109 | BOOST_TEST(wp2.weak_use_count() == wp.weak_use_count()); |
| 102 | 110 | } |
| 103 | 111 | |
| 104 | 112 | { |
| … |
… |
void shared_ptr_constructor()
|
| 108 | 116 | boost::weak_ptr<int> wp(sp); |
| 109 | 117 | BOOST_TEST(wp.use_count() == sp.use_count()); |
| 110 | 118 | BOOST_TEST(wp.use_count() == 1); |
| | 119 | BOOST_TEST(wp.weak_use_count() == 1); |
| 111 | 120 | boost::shared_ptr<int> sp2(wp); |
| 112 | 121 | BOOST_TEST(wp.use_count() == 2); |
| | 122 | BOOST_TEST(wp.weak_use_count() == 1); |
| 113 | 123 | BOOST_TEST(!(sp < sp2 || sp2 < sp)); |
| 114 | 124 | } |
| 115 | 125 | |
| … |
… |
void shared_ptr_constructor()
|
| 117 | 127 | boost::weak_ptr<void> wp(sp); |
| 118 | 128 | BOOST_TEST(wp.use_count() == sp.use_count()); |
| 119 | 129 | BOOST_TEST(wp.use_count() == 1); |
| | 130 | BOOST_TEST(wp.weak_use_count() == 1); |
| 120 | 131 | boost::shared_ptr<void> sp2(wp); |
| 121 | 132 | BOOST_TEST(wp.use_count() == 2); |
| | 133 | BOOST_TEST(wp.weak_use_count() == 1); |
| 122 | 134 | BOOST_TEST(!(sp < sp2 || sp2 < sp)); |
| 123 | 135 | } |
| 124 | 136 | } |
| … |
… |
void shared_ptr_constructor()
|
| 130 | 142 | boost::weak_ptr<int> wp(sp); |
| 131 | 143 | BOOST_TEST(wp.use_count() == sp.use_count()); |
| 132 | 144 | BOOST_TEST(wp.use_count() == 1); |
| | 145 | BOOST_TEST(wp.weak_use_count() == 1); |
| 133 | 146 | boost::shared_ptr<int> sp2(wp); |
| 134 | 147 | BOOST_TEST(wp.use_count() == 2); |
| | 148 | BOOST_TEST(wp.weak_use_count() == 1); |
| 135 | 149 | BOOST_TEST(!(sp < sp2 || sp2 < sp)); |
| 136 | 150 | } |
| 137 | 151 | |
| … |
… |
void shared_ptr_constructor()
|
| 139 | 153 | boost::weak_ptr<void> wp(sp); |
| 140 | 154 | BOOST_TEST(wp.use_count() == sp.use_count()); |
| 141 | 155 | BOOST_TEST(wp.use_count() == 1); |
| | 156 | BOOST_TEST(wp.weak_use_count() == 1); |
| 142 | 157 | boost::shared_ptr<void> sp2(wp); |
| 143 | 158 | BOOST_TEST(wp.use_count() == 2); |
| | 159 | BOOST_TEST(wp.weak_use_count() == 1); |
| 144 | 160 | BOOST_TEST(!(sp < sp2 || sp2 < sp)); |
| 145 | 161 | } |
| 146 | 162 | } |
| … |
… |
void shared_ptr_constructor()
|
| 150 | 166 | |
| 151 | 167 | boost::weak_ptr<void> wp(sp); |
| 152 | 168 | BOOST_TEST(wp.use_count() == sp.use_count()); |
| | 169 | BOOST_TEST(wp.weak_use_count() == sp.weak_use_count()); |
| 153 | 170 | } |
| 154 | 171 | |
| 155 | 172 | { |
| … |
… |
void copy_constructor()
|
| 224 | 241 | boost::weak_ptr<int> wp; |
| 225 | 242 | boost::weak_ptr<int> wp2(wp); |
| 226 | 243 | BOOST_TEST(wp2.use_count() == wp.use_count()); |
| | 244 | BOOST_TEST(wp2.weak_use_count() == wp.weak_use_count()); |
| 227 | 245 | BOOST_TEST(wp2.use_count() == 0); |
| | 246 | BOOST_TEST(wp2.weak_use_count() == 0); |
| 228 | 247 | } |
| 229 | 248 | |
| 230 | 249 | { |
| … |
… |
void copy_constructor()
|
| 238 | 257 | boost::weak_ptr<incomplete> wp; |
| 239 | 258 | boost::weak_ptr<incomplete> wp2(wp); |
| 240 | 259 | BOOST_TEST(wp2.use_count() == wp.use_count()); |
| | 260 | BOOST_TEST(wp2.weak_use_count() == wp.weak_use_count()); |
| 241 | 261 | BOOST_TEST(wp2.use_count() == 0); |
| | 262 | BOOST_TEST(wp2.weak_use_count() == 0); |
| 242 | 263 | } |
| 243 | 264 | |
| 244 | 265 | { |
| … |
… |
void copy_constructor()
|
| 247 | 268 | |
| 248 | 269 | boost::weak_ptr<int> wp2(wp); |
| 249 | 270 | BOOST_TEST(wp2.use_count() == wp.use_count()); |
| | 271 | BOOST_TEST(wp2.weak_use_count() == wp.weak_use_count()); |
| 250 | 272 | BOOST_TEST(wp2.use_count() == 1); |
| | 273 | BOOST_TEST(wp2.weak_use_count() == 2); |
| 251 | 274 | BOOST_TEST(!(wp < wp2 || wp2 < wp)); |
| 252 | 275 | |
| 253 | 276 | sp.reset(); |
| … |
… |
void copy_constructor()
|
| 255 | 278 | |
| 256 | 279 | boost::weak_ptr<int> wp3(wp); |
| 257 | 280 | BOOST_TEST(wp3.use_count() == wp.use_count()); |
| | 281 | BOOST_TEST(wp3.weak_use_count() == wp.weak_use_count()); |
| 258 | 282 | BOOST_TEST(wp3.use_count() == 0); |
| | 283 | BOOST_TEST(wp3.weak_use_count() == 3); |
| 259 | 284 | BOOST_TEST(!(wp < wp3 || wp3 < wp)); |
| 260 | 285 | } |
| 261 | 286 | |
| … |
… |
void copy_constructor()
|
| 265 | 290 | |
| 266 | 291 | boost::weak_ptr<int> wp2(wp); |
| 267 | 292 | BOOST_TEST(wp2.use_count() == wp.use_count()); |
| | 293 | BOOST_TEST(wp2.weak_use_count() == wp.weak_use_count()); |
| 268 | 294 | BOOST_TEST(wp2.use_count() == 1); |
| | 295 | BOOST_TEST(wp2.weak_use_count() == 2); |
| 269 | 296 | BOOST_TEST(!(wp < wp2 || wp2 < wp)); |
| 270 | 297 | |
| 271 | 298 | sp.reset(); |
| … |
… |
void copy_constructor()
|
| 273 | 300 | |
| 274 | 301 | boost::weak_ptr<int> wp3(wp); |
| 275 | 302 | BOOST_TEST(wp3.use_count() == wp.use_count()); |
| | 303 | BOOST_TEST(wp3.weak_use_count() == wp.weak_use_count()); |
| 276 | 304 | BOOST_TEST(wp3.use_count() == 0); |
| | 305 | BOOST_TEST(wp3.weak_use_count() == 3); |
| 277 | 306 | BOOST_TEST(!(wp < wp3 || wp3 < wp)); |
| 278 | 307 | } |
| 279 | 308 | |
| … |
… |
void copy_constructor()
|
| 283 | 312 | |
| 284 | 313 | boost::weak_ptr<void> wp2(wp); |
| 285 | 314 | BOOST_TEST(wp2.use_count() == wp.use_count()); |
| | 315 | BOOST_TEST(wp2.weak_use_count() == wp.weak_use_count()); |
| 286 | 316 | BOOST_TEST(wp2.use_count() == 1); |
| | 317 | BOOST_TEST(wp2.weak_use_count() == 2); |
| 287 | 318 | BOOST_TEST(!(wp < wp2 || wp2 < wp)); |
| 288 | 319 | |
| 289 | 320 | sp.reset(); |
| … |
… |
void copy_constructor()
|
| 291 | 322 | |
| 292 | 323 | boost::weak_ptr<void> wp3(wp); |
| 293 | 324 | BOOST_TEST(wp3.use_count() == wp.use_count()); |
| | 325 | BOOST_TEST(wp3.weak_use_count() == wp.weak_use_count()); |
| 294 | 326 | BOOST_TEST(wp3.use_count() == 0); |
| | 327 | BOOST_TEST(wp3.weak_use_count() == 3); |
| 295 | 328 | BOOST_TEST(!(wp < wp3 || wp3 < wp)); |
| 296 | 329 | } |
| 297 | 330 | |
-
diff --git a/libs/smart_ptr/weak_ptr.htm b/libs/smart_ptr/weak_ptr.htm
index 0fa87f7..b839e30 100644
|
a
|
b
|
if(shared_ptr<int> r = q.<A href="#lock" >lock</A>())
|
| 87 | 87 | template<class Y> weak_ptr & <A href="#assignment" >operator=</A>(shared_ptr<Y> const & r); |
| 88 | 88 | |
| 89 | 89 | long <A href="#use_count" >use_count</A>() const; |
| | 90 | long <A href="#weak_use_count" >weak_use_count</A>() const; |
| 90 | 91 | bool <A href="#expired" >expired</A>() const; |
| 91 | 92 | shared_ptr<T> <A href="#lock" >lock</A>() const; |
| 92 | 93 | |
| … |
… |
template<class Y> weak_ptr & operator=(shared_ptr<Y> const &
|
| 151 | 152 | <P><B>Notes:</B> <code>use_count()</code> is not necessarily efficient. Use only |
| 152 | 153 | for debugging and testing purposes, not for production code.</P> |
| 153 | 154 | </blockquote> |
| | 155 | <h3><a name="weak_use_count">weak_use_count</a></h3> |
| | 156 | <pre>long weak_use_count() const;</pre> |
| | 157 | <blockquote> |
| | 158 | <p><b>Returns:</b> 0 if <STRONG>*this</STRONG> is <EM>empty</EM>; otherwise, the |
| | 159 | number of <b>weak_ptr</b> objects that <EM>share ownership</EM> with <STRONG>*this</STRONG>.</p> |
| | 160 | <p><b>Throws:</b> nothing.</p> |
| | 161 | <P><B>Notes:</B> <code>weak_use_count()</code> is not necessarily efficient. Use only |
| | 162 | for debugging and testing purposes, not for production code.</P> |
| | 163 | </blockquote> |
| 154 | 164 | <h3><a name="expired">expired</a></h3> |
| 155 | 165 | <pre>bool expired() const;</pre> |
| 156 | 166 | <blockquote> |