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
+6 -19
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);
}