Add mixed shared_count/weak_count operator< overloads to avoid refcount manipulation

This commit is contained in:
Peter Dimov
2020-05-31 21:12:12 +03:00
parent 951ff783b5
commit 62b0e5cdf4

View File

@ -494,11 +494,13 @@ public:
return a.pi_ == b.pi_;
}
friend inline bool operator<(shared_count const & a, shared_count const & b) BOOST_SP_NOEXCEPT
bool operator<( shared_count const & r ) const BOOST_SP_NOEXCEPT
{
return std::less<sp_counted_base *>()( a.pi_, b.pi_ );
return std::less<sp_counted_base *>()( pi_, r.pi_ );
}
bool operator<( weak_count const & r ) const BOOST_SP_NOEXCEPT;
void * get_deleter( sp_typeinfo_ const & ti ) const BOOST_SP_NOEXCEPT
{
return pi_? pi_->get_deleter( ti ): 0;
@ -625,9 +627,14 @@ public:
return a.pi_ == b.pi_;
}
friend inline bool operator<(weak_count const & a, weak_count const & b) BOOST_SP_NOEXCEPT
bool operator<( weak_count const & r ) const BOOST_SP_NOEXCEPT
{
return std::less<sp_counted_base *>()(a.pi_, b.pi_);
return std::less<sp_counted_base *>()( pi_, r.pi_ );
}
bool operator<( shared_count const & r ) const BOOST_SP_NOEXCEPT
{
return std::less<sp_counted_base *>()( pi_, r.pi_ );
}
};
@ -653,6 +660,11 @@ inline shared_count::shared_count( weak_count const & r, sp_nothrow_tag ) BOOST_
}
}
inline bool shared_count::operator<( weak_count const & r ) const BOOST_SP_NOEXCEPT
{
return std::less<sp_counted_base *>()( pi_, r.pi_ );
}
} // namespace detail
} // namespace boost