class weak_ptr : public __weak_ptr<_Tp>
{
public:
- constexpr weak_ptr() noexcept
- : __weak_ptr<_Tp>() { }
+ constexpr weak_ptr() noexcept = default;
template<typename _Tp1, typename = typename
std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type>
- weak_ptr(const weak_ptr<_Tp1>& __r) noexcept
+ weak_ptr(const shared_ptr<_Tp1>& __r) noexcept
: __weak_ptr<_Tp>(__r) { }
+ weak_ptr(const weak_ptr&) noexcept = default;
+
template<typename _Tp1, typename = typename
std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type>
- weak_ptr(const shared_ptr<_Tp1>& __r) noexcept
+ weak_ptr(const weak_ptr<_Tp1>& __r) noexcept
: __weak_ptr<_Tp>(__r) { }
+ weak_ptr(weak_ptr&&) noexcept = default;
+
+ template<typename _Tp1, typename = typename
+ std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type>
+ weak_ptr(weak_ptr<_Tp1>&& __r) noexcept
+ : __weak_ptr<_Tp>(std::move(__r)) { }
+
+ weak_ptr&
+ operator=(const weak_ptr& __r) noexcept = default;
+
template<typename _Tp1>
weak_ptr&
operator=(const weak_ptr<_Tp1>& __r) noexcept
return *this;
}
+ weak_ptr&
+ operator=(weak_ptr&& __r) noexcept = default;
+
+ template<typename _Tp1>
+ weak_ptr&
+ operator=(weak_ptr<_Tp1>&& __r) noexcept
+ {
+ this->__weak_ptr<_Tp>::operator=(std::move(__r));
+ return *this;
+ }
+
shared_ptr<_Tp>
lock() const noexcept
{ return shared_ptr<_Tp>(*this, std::nothrow); }
class __weak_count
{
public:
- constexpr __weak_count() noexcept : _M_pi(0)
+ constexpr __weak_count() noexcept : _M_pi(nullptr)
{ }
__weak_count(const __shared_count<_Lp>& __r) noexcept
: _M_pi(__r._M_pi)
{
- if (_M_pi != 0)
+ if (_M_pi != nullptr)
_M_pi->_M_weak_add_ref();
}
- __weak_count(const __weak_count<_Lp>& __r) noexcept
+ __weak_count(const __weak_count& __r) noexcept
: _M_pi(__r._M_pi)
{
- if (_M_pi != 0)
+ if (_M_pi != nullptr)
_M_pi->_M_weak_add_ref();
}
+ __weak_count(__weak_count&& __r) noexcept
+ : _M_pi(__r._M_pi)
+ { __r._M_pi = nullptr; }
+
~__weak_count() noexcept
{
- if (_M_pi != 0)
+ if (_M_pi != nullptr)
_M_pi->_M_weak_release();
}
- __weak_count<_Lp>&
+ __weak_count&
operator=(const __shared_count<_Lp>& __r) noexcept
{
_Sp_counted_base<_Lp>* __tmp = __r._M_pi;
- if (__tmp != 0)
+ if (__tmp != nullptr)
__tmp->_M_weak_add_ref();
- if (_M_pi != 0)
+ if (_M_pi != nullptr)
_M_pi->_M_weak_release();
_M_pi = __tmp;
return *this;
}
- __weak_count<_Lp>&
- operator=(const __weak_count<_Lp>& __r) noexcept
+ __weak_count&
+ operator=(const __weak_count& __r) noexcept
{
_Sp_counted_base<_Lp>* __tmp = __r._M_pi;
- if (__tmp != 0)
+ if (__tmp != nullptr)
__tmp->_M_weak_add_ref();
- if (_M_pi != 0)
+ if (_M_pi != nullptr)
_M_pi->_M_weak_release();
_M_pi = __tmp;
return *this;
}
+ __weak_count&
+ operator=(__weak_count&& __r) noexcept
+ {
+ if (_M_pi != nullptr)
+ _M_pi->_M_weak_release();
+ _M_pi = __r._M_pi;
+ __r._M_pi = nullptr;
+ return *this;
+ }
+
void
- _M_swap(__weak_count<_Lp>& __r) noexcept
+ _M_swap(__weak_count& __r) noexcept
{
_Sp_counted_base<_Lp>* __tmp = __r._M_pi;
__r._M_pi = _M_pi;
long
_M_get_use_count() const noexcept
- { return _M_pi != 0 ? _M_pi->_M_get_use_count() : 0; }
+ { return _M_pi != nullptr ? _M_pi->_M_get_use_count() : 0; }
bool
_M_less(const __weak_count& __rhs) const noexcept
typedef _Tp element_type;
constexpr __weak_ptr() noexcept
- : _M_ptr(0), _M_refcount()
+ : _M_ptr(nullptr), _M_refcount()
{ }
__weak_ptr(const __weak_ptr&) noexcept = default;
- __weak_ptr& operator=(const __weak_ptr&) noexcept = default;
+
~__weak_ptr() = default;
// The "obvious" converting constructor implementation:
: _M_ptr(__r._M_ptr), _M_refcount(__r._M_refcount)
{ }
+ __weak_ptr(__weak_ptr&& __r) noexcept
+ : _M_ptr(__r._M_ptr), _M_refcount(std::move(__r._M_refcount))
+ { __r._M_ptr = nullptr; }
+
+ template<typename _Tp1, typename = typename
+ std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type>
+ __weak_ptr(__weak_ptr<_Tp1, _Lp>&& __r) noexcept
+ : _M_ptr(__r.lock().get()), _M_refcount(std::move(__r._M_refcount))
+ { __r._M_ptr = nullptr; }
+
+ __weak_ptr&
+ operator=(const __weak_ptr& __r) noexcept = default;
+
template<typename _Tp1>
__weak_ptr&
operator=(const __weak_ptr<_Tp1, _Lp>& __r) noexcept
return *this;
}
+ __weak_ptr&
+ operator=(__weak_ptr&& __r) noexcept
+ {
+ _M_ptr = __r._M_ptr;
+ _M_refcount = std::move(__r._M_refcount);
+ __r._M_ptr = nullptr;
+ return *this;
+ }
+
+ template<typename _Tp1>
+ __weak_ptr&
+ operator=(__weak_ptr<_Tp1, _Lp>&& __r) noexcept
+ {
+ _M_ptr = __r.lock().get();
+ _M_refcount = std::move(__r._M_refcount);
+ __r._M_ptr = nullptr;
+ return *this;
+ }
+
__shared_ptr<_Tp, _Lp>
lock() const noexcept
{ return __shared_ptr<element_type, _Lp>(*this, std::nothrow); }