weak_ptr made thread safe, shared->weak conversions, lightweight_mutex added.

[SVN r12786]
This commit is contained in:
Peter Dimov
2002-02-12 16:55:25 +00:00
parent cd8dea78e6
commit 1b69c14f45
8 changed files with 429 additions and 43 deletions
+18
View File
@@ -97,6 +97,10 @@ public:
// generated copy constructor, assignment, destructor are fine
explicit shared_ptr(weak_ptr<T> const & r): px(r.px), pn(r.pn) // may throw
{
}
template<typename Y>
shared_ptr(shared_ptr<Y> const & r): px(r.px), pn(r.pn) // never throws
{
@@ -191,6 +195,20 @@ public:
return pn.use_count();
}
// implicit conversion to "bool"
typedef long (this_type::*bool_type)() const;
operator bool_type() const // never throws
{
return px == 0? 0: &this_type::use_count;
}
bool operator! () const // never throws
{
return px == 0;
}
void swap(shared_ptr<T> & other) // never throws
{
std::swap(px, other.px);