From 62b0e5cdf471e6862a566d5b98362d8decc28f76 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 31 May 2020 21:12:12 +0300 Subject: [PATCH] Add mixed shared_count/weak_count operator< overloads to avoid refcount manipulation --- .../boost/smart_ptr/detail/shared_count.hpp | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/include/boost/smart_ptr/detail/shared_count.hpp b/include/boost/smart_ptr/detail/shared_count.hpp index 69cc915..85e6b1f 100644 --- a/include/boost/smart_ptr/detail/shared_count.hpp +++ b/include/boost/smart_ptr/detail/shared_count.hpp @@ -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()( a.pi_, b.pi_ ); + return std::less()( 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()(a.pi_, b.pi_); + return std::less()( pi_, r.pi_ ); + } + + bool operator<( shared_count const & r ) const BOOST_SP_NOEXCEPT + { + return std::less()( 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()( pi_, r.pi_ ); +} + } // namespace detail } // namespace boost