weak_ptr converting constructor removed; operator< can now take different types to aid ownership tests.

[SVN r16376]
This commit is contained in:
Peter Dimov
2002-11-23 12:47:38 +00:00
parent fadc0716ce
commit 5dd2c62132
3 changed files with 11 additions and 30 deletions

View File

@@ -272,7 +272,7 @@ public:
pn.swap(other.pn);
}
bool _internal_less(this_type const & rhs) const // implementation detail, never throws
template<class Y> bool _internal_less(shared_ptr<Y> const & rhs) const
{
return pn < rhs.pn;
}
@@ -321,7 +321,7 @@ template<class T> inline bool operator!=(shared_ptr<T> const & a, shared_ptr<T>
#endif
template<class T> inline bool operator<(shared_ptr<T> const & a, shared_ptr<T> const & b)
template<class T, class U> inline bool operator<(shared_ptr<T> const & a, shared_ptr<U> const & b)
{
return a._internal_less(b);
}

View File

@@ -45,7 +45,7 @@ public:
//
// The simple implementation of the converting constructor:
// The "obvious" converting constructor implementation:
//
// template<class Y>
// weak_ptr(weak_ptr<Y> const & r): px(r.px), pn(r.pn) // never throws
@@ -60,23 +60,10 @@ public:
// It is not possible to avoid spurious access violations since
// in multithreaded programs r.px may be invalidated at any point.
//
// A safe conversion between weak_ptr<T> and weak_ptr<Y> must involve
// a temporary shared_ptr.
// A weak_ptr<T> can safely be obtained from a weak_ptr<U> by using
//
// It is not yet clear whether the converting constructor should be
// present at all, or it's better to require an explicit make_shared call.
// weak_ptr<T> wpt = make_shared(wpu);
//
// The only case for the converting constructor is the weak_ptr<T> -> weak_ptr<cv void>
// conversion.
//
template<class Y>
weak_ptr(weak_ptr<Y> const & r) // never throws
{
shared_ptr<Y> tmp = make_shared(r);
px = tmp.px;
pn = tmp.pn;
}
template<class Y>
weak_ptr(shared_ptr<Y> const & r): px(r.px), pn(r.pn) // never throws
@@ -116,13 +103,13 @@ public:
pn.swap(other.pn);
}
void _internal_assign(T * px2, detail::shared_count const & pn2) // implementation detail
void _internal_assign(T * px2, detail::shared_count const & pn2)
{
px = px2;
pn = pn2;
}
bool _internal_less(this_type const & rhs) const // implementation detail, never throws
template<class Y> bool _internal_less(weak_ptr<Y> const & rhs) const
{
return pn < rhs.pn;
}
@@ -144,7 +131,7 @@ private:
}; // weak_ptr
template<class T> inline bool operator<(weak_ptr<T> const & a, weak_ptr<T> const & b)
template<class T, class U> inline bool operator<(weak_ptr<T> const & a, weak_ptr<U> const & b)
{
return a._internal_less(b);
}

View File

@@ -773,11 +773,6 @@ void weak_ptr_constructor()
catch(boost::bad_weak_ptr)
{
}
{
boost::weak_ptr<Y> wp2(wp);
boost::weak_ptr<X> wp3(wp);
}
}
void auto_ptr_constructor()
@@ -2256,13 +2251,13 @@ template<class T> void test_ne(T const & a, T const & b)
BOOST_TEST(!(a < b && b < a));
}
void test_shared(boost::weak_ptr<void> const & a, boost::weak_ptr<void> const & b)
template<class T, class U> void test_shared(boost::weak_ptr<T> const & a, boost::weak_ptr<U> const & b)
{
BOOST_TEST(!(a < b));
BOOST_TEST(!(b < a));
}
void test_nonshared(boost::weak_ptr<void> const & a, boost::weak_ptr<void> const & b)
template<class T, class U> void test_nonshared(boost::weak_ptr<T> const & a, boost::weak_ptr<U> const & b)
{
BOOST_TEST(a < b || b < a);
BOOST_TEST(!(a < b && b < a));
@@ -2381,7 +2376,7 @@ void test()
BOOST_TEST(wp3.use_count() == 1);
test_shared(wp2, wp3);
weak_ptr<X> wp4(wp3);
weak_ptr<X> wp4 = boost::make_shared(wp3);
BOOST_TEST(wp4.use_count() == 1);
test_shared(wp2, wp4);
@@ -2390,7 +2385,6 @@ void test()
test_is_zero(boost::make_shared(wp1));
wp1 = p4;
wp1 = wp3;
wp1 = wp2;
BOOST_TEST(wp1.use_count() == 1);