From 513cd15378259284f212dd725d9989e36058e206 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 21 Apr 2019 22:43:04 +0300 Subject: [PATCH] Add aliasing constructors to weak_ptr. Closes #67. --- include/boost/smart_ptr/weak_ptr.hpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/include/boost/smart_ptr/weak_ptr.hpp b/include/boost/smart_ptr/weak_ptr.hpp index 54d9ef3..ec451bd 100644 --- a/include/boost/smart_ptr/weak_ptr.hpp +++ b/include/boost/smart_ptr/weak_ptr.hpp @@ -137,6 +137,23 @@ public: boost::detail::sp_assert_convertible< Y, T >(); } + // aliasing + template weak_ptr(shared_ptr const & r, element_type * p) BOOST_SP_NOEXCEPT: px( p ), pn( r.pn ) + { + } + + template weak_ptr(weak_ptr const & r, element_type * p) BOOST_SP_NOEXCEPT: px( p ), pn( r.pn ) + { + } + +#if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) + + template weak_ptr(weak_ptr && r, element_type * p) BOOST_SP_NOEXCEPT: px( p ), pn( std::move( r.pn ) ) + { + } + +#endif + #if !defined(BOOST_MSVC) || (BOOST_MSVC >= 1300) template @@ -194,6 +211,11 @@ public: return pn.empty(); } + bool empty() const BOOST_SP_NOEXCEPT // extension, not in std::weak_ptr + { + return pn.empty(); + } + void reset() BOOST_SP_NOEXCEPT { this_type().swap(*this);