weak_ptr::operator< is now stable, shared_ptr_test has much better coverage.

[SVN r12769]
This commit is contained in:
Peter Dimov
2002-02-09 12:34:05 +00:00
parent d2e20cf56c
commit 6f7b927641
4 changed files with 145 additions and 4 deletions
+22
View File
@@ -25,6 +25,8 @@
#include <boost/checked_delete.hpp>
#include <boost/detail/atomic_count.hpp>
#include <functional> // for std::less
namespace boost
{
@@ -215,6 +217,16 @@ public:
{
return pi_->use_count() == 1;
}
friend inline bool operator==(shared_count const & a, shared_count const & b)
{
return a.pi_ == b.pi_;
}
friend inline bool operator<(shared_count const & a, shared_count const & b)
{
return std::less<counted_base *>()(a.pi_, b.pi_);
}
};
class weak_count
@@ -275,6 +287,16 @@ public:
{
return pi_->use_count();
}
friend inline bool operator==(weak_count const & a, weak_count const & b)
{
return a.pi_ == b.pi_;
}
friend inline bool operator<(weak_count const & a, weak_count const & b)
{
return std::less<counted_base *>()(a.pi_, b.pi_);
}
};
} // namespace detail
+1
View File
@@ -29,6 +29,7 @@
#include <memory> // for std::auto_ptr
#include <algorithm> // for std::swap
#include <functional> // for std::less
#include <typeinfo> // for std::bad_cast
#ifdef BOOST_MSVC // moved here to work around VC++ compiler crash
# pragma warning(push)
+7 -2
View File
@@ -22,7 +22,7 @@
#include <boost/detail/shared_count.hpp>
#include <algorithm> // for std::swap
#include <functional> // for std::less
#include <typeinfo> // for std::bad_cast
#ifdef BOOST_MSVC // moved here to work around VC++ compiler crash
# pragma warning(push)
@@ -133,6 +133,11 @@ public:
pn.swap(other.pn);
}
bool less(this_type const & rhs) const // implementation detail, never throws
{
return pn < rhs.pn;
}
// Tasteless as this may seem, making all members public allows member templates
// to work in the absence of member template friends. (Matthew Langston)
@@ -161,7 +166,7 @@ template<class T, class U> inline bool operator!=(weak_ptr<T> const & a, weak_pt
template<class T> inline bool operator<(weak_ptr<T> const & a, weak_ptr<T> const & b)
{
return std::less<T*>()(a.get(), b.get());
return a.less(b);
}
template<class T> void swap(weak_ptr<T> & a, weak_ptr<T> & b)