/// 2.2.3.10 shared_ptr get_deleter (experimental)
template<typename _Del, typename _Tp, _Lock_policy _Lp>
inline _Del*
- get_deleter(const __shared_ptr<_Tp, _Lp>& __p)
+ get_deleter(const __shared_ptr<_Tp, _Lp>& __p) noexcept
{
#ifdef __GXX_RTTI
return static_cast<_Del*>(__p._M_get_deleter(typeid(_Del)));
* @brief Construct an empty %shared_ptr.
* @post use_count()==0 && get()==0
*/
- constexpr shared_ptr()
+ constexpr shared_ptr() noexcept
: __shared_ptr<_Tp>() { }
/**
* @endcode
*/
template<typename _Tp1>
- shared_ptr(const shared_ptr<_Tp1>& __r, _Tp* __p)
+ shared_ptr(const shared_ptr<_Tp1>& __r, _Tp* __p) noexcept
: __shared_ptr<_Tp>(__r, __p) { }
/**
*/
template<typename _Tp1, typename = typename
std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type>
- shared_ptr(const shared_ptr<_Tp1>& __r)
+ shared_ptr(const shared_ptr<_Tp1>& __r) noexcept
: __shared_ptr<_Tp>(__r) { }
/**
* @param __r A %shared_ptr rvalue.
* @post *this contains the old value of @a __r, @a __r is empty.
*/
- shared_ptr(shared_ptr&& __r)
+ shared_ptr(shared_ptr&& __r) noexcept
: __shared_ptr<_Tp>(std::move(__r)) { }
/**
*/
template<typename _Tp1, typename = typename
std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type>
- shared_ptr(shared_ptr<_Tp1>&& __r)
+ shared_ptr(shared_ptr<_Tp1>&& __r) noexcept
: __shared_ptr<_Tp>(std::move(__r)) { }
/**
* @param __p A null pointer constant.
* @post use_count() == 0 && get() == nullptr
*/
- constexpr shared_ptr(nullptr_t __p)
+ constexpr shared_ptr(nullptr_t __p) noexcept
: __shared_ptr<_Tp>(__p) { }
template<typename _Tp1>
shared_ptr&
- operator=(const shared_ptr<_Tp1>& __r) // never throws
+ operator=(const shared_ptr<_Tp1>& __r) noexcept
{
this->__shared_ptr<_Tp>::operator=(__r);
return *this;
#endif
shared_ptr&
- operator=(shared_ptr&& __r)
+ operator=(shared_ptr&& __r) noexcept
{
this->__shared_ptr<_Tp>::operator=(std::move(__r));
return *this;
template<class _Tp1>
shared_ptr&
- operator=(shared_ptr<_Tp1>&& __r)
+ operator=(shared_ptr<_Tp1>&& __r) noexcept
{
this->__shared_ptr<_Tp>::operator=(std::move(__r));
return *this;
// 20.8.13.2.9 shared_ptr specialized algorithms.
template<typename _Tp>
inline void
- swap(shared_ptr<_Tp>& __a, shared_ptr<_Tp>& __b)
+ swap(shared_ptr<_Tp>& __a, shared_ptr<_Tp>& __b) noexcept
{ __a.swap(__b); }
// 20.8.13.2.10 shared_ptr casts.
template<typename _Tp, typename _Tp1>
inline shared_ptr<_Tp>
- static_pointer_cast(const shared_ptr<_Tp1>& __r)
+ static_pointer_cast(const shared_ptr<_Tp1>& __r) noexcept
{ return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get())); }
template<typename _Tp, typename _Tp1>
inline shared_ptr<_Tp>
- const_pointer_cast(const shared_ptr<_Tp1>& __r)
+ const_pointer_cast(const shared_ptr<_Tp1>& __r) noexcept
{ return shared_ptr<_Tp>(__r, const_cast<_Tp*>(__r.get())); }
template<typename _Tp, typename _Tp1>
inline shared_ptr<_Tp>
- dynamic_pointer_cast(const shared_ptr<_Tp1>& __r)
+ dynamic_pointer_cast(const shared_ptr<_Tp1>& __r) noexcept
{
if (_Tp* __p = dynamic_cast<_Tp*>(__r.get()))
return shared_ptr<_Tp>(__r, __p);
class weak_ptr : public __weak_ptr<_Tp>
{
public:
- constexpr weak_ptr()
+ constexpr weak_ptr() noexcept
: __weak_ptr<_Tp>() { }
template<typename _Tp1, typename = typename
std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type>
- weak_ptr(const weak_ptr<_Tp1>& __r)
+ weak_ptr(const weak_ptr<_Tp1>& __r) noexcept
: __weak_ptr<_Tp>(__r) { }
template<typename _Tp1, typename = typename
std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type>
- weak_ptr(const shared_ptr<_Tp1>& __r)
+ weak_ptr(const shared_ptr<_Tp1>& __r) noexcept
: __weak_ptr<_Tp>(__r) { }
template<typename _Tp1>
weak_ptr&
- operator=(const weak_ptr<_Tp1>& __r) // never throws
+ operator=(const weak_ptr<_Tp1>& __r) noexcept
{
this->__weak_ptr<_Tp>::operator=(__r);
return *this;
template<typename _Tp1>
weak_ptr&
- operator=(const shared_ptr<_Tp1>& __r) // never throws
+ operator=(const shared_ptr<_Tp1>& __r) noexcept
{
this->__weak_ptr<_Tp>::operator=(__r);
return *this;
}
shared_ptr<_Tp>
- lock() const // never throws
+ lock() const noexcept
{
#ifdef __GTHREADS
if (this->expired())
// 20.8.13.3.7 weak_ptr specialized algorithms.
template<typename _Tp>
inline void
- swap(weak_ptr<_Tp>& __a, weak_ptr<_Tp>& __b)
+ swap(weak_ptr<_Tp>& __a, weak_ptr<_Tp>& __b) noexcept
{ __a.swap(__b); }
class enable_shared_from_this
{
protected:
- constexpr enable_shared_from_this() { }
+ constexpr enable_shared_from_this() noexcept { }
- enable_shared_from_this(const enable_shared_from_this&) { }
+ enable_shared_from_this(const enable_shared_from_this&) noexcept { }
enable_shared_from_this&
- operator=(const enable_shared_from_this&)
+ operator=(const enable_shared_from_this&) noexcept
{ return *this; }
~enable_shared_from_this() { }
private:
template<typename _Tp1>
void
- _M_weak_assign(_Tp1* __p, const __shared_count<>& __n) const
+ _M_weak_assign(_Tp1* __p, const __shared_count<>& __n) const noexcept
{ _M_weak_this._M_assign(__p, __n); }
template<typename _Tp1>
friend void
__enable_shared_from_this_helper(const __shared_count<>& __pn,
const enable_shared_from_this* __pe,
- const _Tp1* __px)
+ const _Tp1* __px) noexcept
{
if (__pe != 0)
__pe->_M_weak_assign(const_cast<_Tp1*>(__px), __pn);
{
public:
virtual char const*
- what() const throw();
+ what() const noexcept;
virtual ~bad_weak_ptr() throw();
};
: public _Mutex_base<_Lp>
{
public:
- _Sp_counted_base()
+ _Sp_counted_base() noexcept
: _M_use_count(1), _M_weak_count(1) { }
virtual
- ~_Sp_counted_base() // nothrow
+ ~_Sp_counted_base() noexcept
{ }
// Called when _M_use_count drops to zero, to release the resources
// managed by *this.
virtual void
- _M_dispose() = 0; // nothrow
+ _M_dispose() noexcept = 0;
// Called when _M_weak_count drops to zero.
virtual void
- _M_destroy() // nothrow
+ _M_destroy() noexcept
{ delete this; }
virtual void*
_M_add_ref_lock();
void
- _M_release() // nothrow
+ _M_release() noexcept
{
// Be race-detector-friendly. For more info see bits/c++config.
_GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&_M_use_count);
}
void
- _M_weak_add_ref() // nothrow
+ _M_weak_add_ref() noexcept
{ __gnu_cxx::__atomic_add_dispatch(&_M_weak_count, 1); }
void
- _M_weak_release() // nothrow
+ _M_weak_release() noexcept
{
// Be race-detector-friendly. For more info see bits/c++config.
_GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&_M_weak_count);
}
long
- _M_get_use_count() const // nothrow
+ _M_get_use_count() const noexcept
{
// No memory barrier is used here so there is no synchronization
// with other threads.
}
private:
- _Sp_counted_base(_Sp_counted_base const&);
- _Sp_counted_base& operator=(_Sp_counted_base const&);
+ _Sp_counted_base(_Sp_counted_base const&) = delete;
+ _Sp_counted_base& operator=(_Sp_counted_base const&) = delete;
_Atomic_word _M_use_count; // #shared
_Atomic_word _M_weak_count; // #weak + (#shared != 0)
: _M_ptr(__p) { }
virtual void
- _M_dispose() // nothrow
+ _M_dispose() noexcept
{ delete _M_ptr; }
virtual void
- _M_destroy() // nothrow
+ _M_destroy() noexcept
{ delete this; }
virtual void*
template<>
inline void
- _Sp_counted_ptr<nullptr_t, _S_single>::_M_dispose() { }
+ _Sp_counted_ptr<nullptr_t, _S_single>::_M_dispose() noexcept { }
template<>
inline void
- _Sp_counted_ptr<nullptr_t, _S_mutex>::_M_dispose() { }
+ _Sp_counted_ptr<nullptr_t, _S_mutex>::_M_dispose() noexcept { }
template<>
inline void
- _Sp_counted_ptr<nullptr_t, _S_atomic>::_M_dispose() { }
+ _Sp_counted_ptr<nullptr_t, _S_atomic>::_M_dispose() noexcept { }
// Support for custom deleter and/or allocator
template<typename _Ptr, typename _Deleter, typename _Alloc, _Lock_policy _Lp>
: _M_ptr(__p), _M_del(__d, __a) { }
virtual void
- _M_dispose() // nothrow
+ _M_dispose() noexcept
{ _M_del._M_del(_M_ptr); }
virtual void
- _M_destroy() // nothrow
+ _M_destroy() noexcept
{
_My_alloc_type __a(_M_del);
this->~_Sp_counted_deleter();
// Override because the allocator needs to know the dynamic type
virtual void
- _M_destroy() // nothrow
+ _M_destroy() noexcept
{
typedef typename _Alloc::template
rebind<_Sp_counted_ptr_inplace>::other _My_alloc_type;
// Sneaky trick so __shared_ptr can get the managed pointer
virtual void*
- _M_get_deleter(const std::type_info& __ti)
+ _M_get_deleter(const std::type_info& __ti) noexcept
{
#ifdef __GXX_RTTI
return __ti == typeid(_Sp_make_shared_tag)
class __shared_count
{
public:
- constexpr __shared_count() : _M_pi(0) // nothrow
+ constexpr __shared_count() noexcept : _M_pi(0)
{ }
template<typename _Ptr>
// Throw bad_weak_ptr when __r._M_get_use_count() == 0.
explicit __shared_count(const __weak_count<_Lp>& __r);
- ~__shared_count() // nothrow
+ ~__shared_count() noexcept
{
if (_M_pi != 0)
_M_pi->_M_release();
}
- __shared_count(const __shared_count& __r)
- : _M_pi(__r._M_pi) // nothrow
+ __shared_count(const __shared_count& __r) noexcept
+ : _M_pi(__r._M_pi)
{
if (_M_pi != 0)
_M_pi->_M_add_ref_copy();
}
__shared_count&
- operator=(const __shared_count& __r) // nothrow
+ operator=(const __shared_count& __r) noexcept
{
_Sp_counted_base<_Lp>* __tmp = __r._M_pi;
if (__tmp != _M_pi)
}
void
- _M_swap(__shared_count& __r) // nothrow
+ _M_swap(__shared_count& __r) noexcept
{
_Sp_counted_base<_Lp>* __tmp = __r._M_pi;
__r._M_pi = _M_pi;
}
long
- _M_get_use_count() const // nothrow
+ _M_get_use_count() const noexcept
{ return _M_pi != 0 ? _M_pi->_M_get_use_count() : 0; }
bool
- _M_unique() const // nothrow
+ _M_unique() const noexcept
{ return this->_M_get_use_count() == 1; }
void*
- _M_get_deleter(const std::type_info& __ti) const
+ _M_get_deleter(const std::type_info& __ti) const noexcept
{ return _M_pi ? _M_pi->_M_get_deleter(__ti) : 0; }
bool
- _M_less(const __shared_count& __rhs) const
+ _M_less(const __shared_count& __rhs) const noexcept
{ return std::less<_Sp_counted_base<_Lp>*>()(this->_M_pi, __rhs._M_pi); }
bool
- _M_less(const __weak_count<_Lp>& __rhs) const
+ _M_less(const __weak_count<_Lp>& __rhs) const noexcept
{ return std::less<_Sp_counted_base<_Lp>*>()(this->_M_pi, __rhs._M_pi); }
// Friend function injected into enclosing namespace and found by ADL
friend inline bool
- operator==(const __shared_count& __a, const __shared_count& __b)
+ operator==(const __shared_count& __a, const __shared_count& __b) noexcept
{ return __a._M_pi == __b._M_pi; }
private:
class __weak_count
{
public:
- constexpr __weak_count() : _M_pi(0) // nothrow
+ constexpr __weak_count() noexcept : _M_pi(0)
{ }
- __weak_count(const __shared_count<_Lp>& __r) : _M_pi(__r._M_pi) // nothrow
+ __weak_count(const __shared_count<_Lp>& __r) noexcept
+ : _M_pi(__r._M_pi)
{
if (_M_pi != 0)
_M_pi->_M_weak_add_ref();
}
- __weak_count(const __weak_count<_Lp>& __r) : _M_pi(__r._M_pi) // nothrow
+ __weak_count(const __weak_count<_Lp>& __r) noexcept
+ : _M_pi(__r._M_pi)
{
if (_M_pi != 0)
_M_pi->_M_weak_add_ref();
}
- ~__weak_count() // nothrow
+ ~__weak_count() noexcept
{
if (_M_pi != 0)
_M_pi->_M_weak_release();
}
__weak_count<_Lp>&
- operator=(const __shared_count<_Lp>& __r) // nothrow
+ operator=(const __shared_count<_Lp>& __r) noexcept
{
_Sp_counted_base<_Lp>* __tmp = __r._M_pi;
if (__tmp != 0)
}
__weak_count<_Lp>&
- operator=(const __weak_count<_Lp>& __r) // nothrow
+ operator=(const __weak_count<_Lp>& __r) noexcept
{
_Sp_counted_base<_Lp>* __tmp = __r._M_pi;
if (__tmp != 0)
}
void
- _M_swap(__weak_count<_Lp>& __r) // nothrow
+ _M_swap(__weak_count<_Lp>& __r) noexcept
{
_Sp_counted_base<_Lp>* __tmp = __r._M_pi;
__r._M_pi = _M_pi;
}
long
- _M_get_use_count() const // nothrow
+ _M_get_use_count() const noexcept
{ return _M_pi != 0 ? _M_pi->_M_get_use_count() : 0; }
bool
- _M_less(const __weak_count& __rhs) const
+ _M_less(const __weak_count& __rhs) const noexcept
{ return std::less<_Sp_counted_base<_Lp>*>()(this->_M_pi, __rhs._M_pi); }
bool
- _M_less(const __shared_count<_Lp>& __rhs) const
+ _M_less(const __shared_count<_Lp>& __rhs) const noexcept
{ return std::less<_Sp_counted_base<_Lp>*>()(this->_M_pi, __rhs._M_pi); }
// Friend function injected into enclosing namespace and found by ADL
friend inline bool
- operator==(const __weak_count& __a, const __weak_count& __b)
+ operator==(const __weak_count& __a, const __weak_count& __b) noexcept
{ return __a._M_pi == __b._M_pi; }
private:
void
__enable_shared_from_this_helper(const __shared_count<_Lp>&,
const __enable_shared_from_this<_Tp1,
- _Lp>*, const _Tp2*);
+ _Lp>*, const _Tp2*) noexcept;
// Friend of enable_shared_from_this.
template<typename _Tp1, typename _Tp2>
void
__enable_shared_from_this_helper(const __shared_count<>&,
const enable_shared_from_this<_Tp1>*,
- const _Tp2*);
+ const _Tp2*) noexcept;
template<_Lock_policy _Lp>
inline void
- __enable_shared_from_this_helper(const __shared_count<_Lp>&, ...)
+ __enable_shared_from_this_helper(const __shared_count<_Lp>&, ...) noexcept
{ }
public:
typedef _Tp element_type;
- constexpr __shared_ptr()
- : _M_ptr(0), _M_refcount() // never throws
+ constexpr __shared_ptr() noexcept
+ : _M_ptr(0), _M_refcount()
{ }
template<typename _Tp1>
{ }
template<typename _Tp1>
- __shared_ptr(const __shared_ptr<_Tp1, _Lp>& __r, _Tp* __p)
+ __shared_ptr(const __shared_ptr<_Tp1, _Lp>& __r, _Tp* __p) noexcept
: _M_ptr(__p), _M_refcount(__r._M_refcount) // never throws
{ }
- // generated copy constructor, assignment, destructor are fine.
+ __shared_ptr(const __shared_ptr&) noexcept = default;
+ __shared_ptr& operator=(const __shared_ptr&) noexcept = default;
+ ~__shared_ptr() = default;
template<typename _Tp1, typename = typename
std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type>
- __shared_ptr(const __shared_ptr<_Tp1, _Lp>& __r)
- : _M_ptr(__r._M_ptr), _M_refcount(__r._M_refcount) // never throws
+ __shared_ptr(const __shared_ptr<_Tp1, _Lp>& __r) noexcept
+ : _M_ptr(__r._M_ptr), _M_refcount(__r._M_refcount)
{ }
- __shared_ptr(__shared_ptr&& __r)
- : _M_ptr(__r._M_ptr), _M_refcount() // never throws
+ __shared_ptr(__shared_ptr&& __r) noexcept
+ : _M_ptr(__r._M_ptr), _M_refcount()
{
_M_refcount._M_swap(__r._M_refcount);
__r._M_ptr = 0;
template<typename _Tp1, typename = typename
std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type>
- __shared_ptr(__shared_ptr<_Tp1, _Lp>&& __r)
- : _M_ptr(__r._M_ptr), _M_refcount() // never throws
+ __shared_ptr(__shared_ptr<_Tp1, _Lp>&& __r) noexcept
+ : _M_ptr(__r._M_ptr), _M_refcount()
{
_M_refcount._M_swap(__r._M_refcount);
__r._M_ptr = 0;
#endif
/* TODO: use delegating constructor */
- constexpr __shared_ptr(nullptr_t)
- : _M_ptr(0), _M_refcount() // never throws
+ constexpr __shared_ptr(nullptr_t) noexcept
+ : _M_ptr(0), _M_refcount()
{ }
template<typename _Tp1>
__shared_ptr&
- operator=(const __shared_ptr<_Tp1, _Lp>& __r) // never throws
+ operator=(const __shared_ptr<_Tp1, _Lp>& __r) noexcept
{
_M_ptr = __r._M_ptr;
_M_refcount = __r._M_refcount; // __shared_count::op= doesn't throw
#endif
__shared_ptr&
- operator=(__shared_ptr&& __r)
+ operator=(__shared_ptr&& __r) noexcept
{
__shared_ptr(std::move(__r)).swap(*this);
return *this;
template<class _Tp1>
__shared_ptr&
- operator=(__shared_ptr<_Tp1, _Lp>&& __r)
+ operator=(__shared_ptr<_Tp1, _Lp>&& __r) noexcept
{
__shared_ptr(std::move(__r)).swap(*this);
return *this;
}
void
- reset() // never throws
+ reset() noexcept
{ __shared_ptr().swap(*this); }
template<typename _Tp1>
// Allow class instantiation when _Tp is [cv-qual] void.
typename std::add_lvalue_reference<_Tp>::type
- operator*() const // never throws
+ operator*() const noexcept
{
_GLIBCXX_DEBUG_ASSERT(_M_ptr != 0);
return *_M_ptr;
}
_Tp*
- operator->() const // never throws
+ operator->() const noexcept
{
_GLIBCXX_DEBUG_ASSERT(_M_ptr != 0);
return _M_ptr;
}
_Tp*
- get() const // never throws
+ get() const noexcept
{ return _M_ptr; }
explicit operator bool() const // never throws
{ return _M_ptr == 0 ? false : true; }
bool
- unique() const // never throws
+ unique() const noexcept
{ return _M_refcount._M_unique(); }
long
- use_count() const // never throws
+ use_count() const noexcept
{ return _M_refcount._M_get_use_count(); }
void
- swap(__shared_ptr<_Tp, _Lp>& __other) // never throws
+ swap(__shared_ptr<_Tp, _Lp>& __other) noexcept
{
std::swap(_M_ptr, __other._M_ptr);
_M_refcount._M_swap(__other._M_refcount);
private:
void*
- _M_get_deleter(const std::type_info& __ti) const
+ _M_get_deleter(const std::type_info& __ti) const noexcept
{ return _M_refcount._M_get_deleter(__ti); }
template<typename _Tp1, _Lock_policy _Lp1> friend class __shared_ptr;
template<typename _Tp1, _Lock_policy _Lp1> friend class __weak_ptr;
template<typename _Del, typename _Tp1, _Lock_policy _Lp1>
- friend _Del* get_deleter(const __shared_ptr<_Tp1, _Lp1>&);
+ friend _Del* get_deleter(const __shared_ptr<_Tp1, _Lp1>&) noexcept;
_Tp* _M_ptr; // Contained pointer.
__shared_count<_Lp> _M_refcount; // Reference counter.
struct _Sp_less : public binary_function<_Sp, _Sp, bool>
{
bool
- operator()(const _Sp& __lhs, const _Sp& __rhs) const
+ operator()(const _Sp& __lhs, const _Sp& __rhs) const noexcept
{
typedef typename _Sp::element_type element_type;
return std::less<element_type*>()(__lhs.get(), __rhs.get());
// 2.2.3.8 shared_ptr specialized algorithms.
template<typename _Tp, _Lock_policy _Lp>
inline void
- swap(__shared_ptr<_Tp, _Lp>& __a, __shared_ptr<_Tp, _Lp>& __b)
+ swap(__shared_ptr<_Tp, _Lp>& __a, __shared_ptr<_Tp, _Lp>& __b) noexcept
{ __a.swap(__b); }
// 2.2.3.9 shared_ptr casts
/// static_pointer_cast
template<typename _Tp, typename _Tp1, _Lock_policy _Lp>
inline __shared_ptr<_Tp, _Lp>
- static_pointer_cast(const __shared_ptr<_Tp1, _Lp>& __r)
+ static_pointer_cast(const __shared_ptr<_Tp1, _Lp>& __r) noexcept
{ return __shared_ptr<_Tp, _Lp>(__r, static_cast<_Tp*>(__r.get())); }
// The seemingly equivalent code:
/// const_pointer_cast
template<typename _Tp, typename _Tp1, _Lock_policy _Lp>
inline __shared_ptr<_Tp, _Lp>
- const_pointer_cast(const __shared_ptr<_Tp1, _Lp>& __r)
+ const_pointer_cast(const __shared_ptr<_Tp1, _Lp>& __r) noexcept
{ return __shared_ptr<_Tp, _Lp>(__r, const_cast<_Tp*>(__r.get())); }
// The seemingly equivalent code:
/// dynamic_pointer_cast
template<typename _Tp, typename _Tp1, _Lock_policy _Lp>
inline __shared_ptr<_Tp, _Lp>
- dynamic_pointer_cast(const __shared_ptr<_Tp1, _Lp>& __r)
+ dynamic_pointer_cast(const __shared_ptr<_Tp1, _Lp>& __r) noexcept
{
if (_Tp* __p = dynamic_cast<_Tp*>(__r.get()))
return __shared_ptr<_Tp, _Lp>(__r, __p);
public:
typedef _Tp element_type;
- constexpr __weak_ptr()
- : _M_ptr(0), _M_refcount() // never throws
+ constexpr __weak_ptr() noexcept
+ : _M_ptr(0), _M_refcount()
{ }
- // Generated copy constructor, assignment, destructor are fine.
+ __weak_ptr(const __weak_ptr&) noexcept = default;
+ __weak_ptr& operator=(const __weak_ptr&) noexcept = default;
+ ~__weak_ptr() = default;
// The "obvious" converting constructor implementation:
//
// in multithreaded programs __r._M_ptr may be invalidated at any point.
template<typename _Tp1, typename = typename
std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type>
- __weak_ptr(const __weak_ptr<_Tp1, _Lp>& __r)
- : _M_refcount(__r._M_refcount) // never throws
+ __weak_ptr(const __weak_ptr<_Tp1, _Lp>& __r) noexcept
+ : _M_refcount(__r._M_refcount)
{ _M_ptr = __r.lock().get(); }
template<typename _Tp1, typename = typename
std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type>
- __weak_ptr(const __shared_ptr<_Tp1, _Lp>& __r)
- : _M_ptr(__r._M_ptr), _M_refcount(__r._M_refcount) // never throws
+ __weak_ptr(const __shared_ptr<_Tp1, _Lp>& __r) noexcept
+ : _M_ptr(__r._M_ptr), _M_refcount(__r._M_refcount)
{ }
template<typename _Tp1>
__weak_ptr&
- operator=(const __weak_ptr<_Tp1, _Lp>& __r) // never throws
+ operator=(const __weak_ptr<_Tp1, _Lp>& __r) noexcept
{
_M_ptr = __r.lock().get();
_M_refcount = __r._M_refcount;
template<typename _Tp1>
__weak_ptr&
- operator=(const __shared_ptr<_Tp1, _Lp>& __r) // never throws
+ operator=(const __shared_ptr<_Tp1, _Lp>& __r) noexcept
{
_M_ptr = __r._M_ptr;
_M_refcount = __r._M_refcount;
}
__shared_ptr<_Tp, _Lp>
- lock() const // never throws
+ lock() const noexcept
{
#ifdef __GTHREADS
// Optimization: avoid throw overhead.
} // XXX MT
long
- use_count() const // never throws
+ use_count() const noexcept
{ return _M_refcount._M_get_use_count(); }
bool
- expired() const // never throws
+ expired() const noexcept
{ return _M_refcount._M_get_use_count() == 0; }
template<typename _Tp1>
{ return _M_refcount._M_less(__rhs._M_refcount); }
void
- reset() // never throws
+ reset() noexcept
{ __weak_ptr().swap(*this); }
void
- swap(__weak_ptr& __s) // never throws
+ swap(__weak_ptr& __s) noexcept
{
std::swap(_M_ptr, __s._M_ptr);
_M_refcount._M_swap(__s._M_refcount);
private:
// Used by __enable_shared_from_this.
void
- _M_assign(_Tp* __ptr, const __shared_count<_Lp>& __refcount)
+ _M_assign(_Tp* __ptr, const __shared_count<_Lp>& __refcount) noexcept
{
_M_ptr = __ptr;
_M_refcount = __refcount;
// 20.8.13.3.7 weak_ptr specialized algorithms.
template<typename _Tp, _Lock_policy _Lp>
inline void
- swap(__weak_ptr<_Tp, _Lp>& __a, __weak_ptr<_Tp, _Lp>& __b)
+ swap(__weak_ptr<_Tp, _Lp>& __a, __weak_ptr<_Tp, _Lp>& __b) noexcept
{ __a.swap(__b); }
template<typename _Tp, typename _Tp1>
class __enable_shared_from_this
{
protected:
- constexpr __enable_shared_from_this() { }
+ constexpr __enable_shared_from_this() noexcept { }
- __enable_shared_from_this(const __enable_shared_from_this&) { }
+ __enable_shared_from_this(const __enable_shared_from_this&) noexcept { }
__enable_shared_from_this&
- operator=(const __enable_shared_from_this&)
+ operator=(const __enable_shared_from_this&) noexcept
{ return *this; }
~__enable_shared_from_this() { }
private:
template<typename _Tp1>
void
- _M_weak_assign(_Tp1* __p, const __shared_count<_Lp>& __n) const
+ _M_weak_assign(_Tp1* __p, const __shared_count<_Lp>& __n) const noexcept
{ _M_weak_this._M_assign(__p, __n); }
template<typename _Tp1>
friend void
__enable_shared_from_this_helper(const __shared_count<_Lp>& __pn,
const __enable_shared_from_this* __pe,
- const _Tp1* __px)
+ const _Tp1* __px) noexcept
{
if (__pe != 0)
__pe->_M_weak_assign(const_cast<_Tp1*>(__px), __pn);