class _Sp_counted_ptr : public _Sp_counted_base<_Lp>
{
public:
+ explicit
_Sp_counted_ptr(_Ptr __p)
: _M_ptr(__p) { }
{ delete this; }
virtual void*
- _M_get_deleter(const std::type_info& __ti)
+ _M_get_deleter(const std::type_info&)
{ return 0; }
_Sp_counted_ptr(const _Sp_counted_ptr&) = delete;
_Ptr _M_ptr; // copy constructor must not throw
};
+ template<>
+ inline void
+ _Sp_counted_ptr<nullptr_t, _S_single>::_M_dispose() { }
+
+ template<>
+ inline void
+ _Sp_counted_ptr<nullptr_t, _S_mutex>::_M_dispose() { }
+
+ template<>
+ inline void
+ _Sp_counted_ptr<nullptr_t, _S_atomic>::_M_dispose() { }
+
// Support for custom deleter and/or allocator
template<typename _Ptr, typename _Deleter, typename _Alloc, _Lock_policy _Lp>
class _Sp_counted_deleter : public _Sp_counted_ptr<_Ptr, _Lp>
_Base_type;
public:
+ explicit
_Sp_counted_ptr_inplace(_Alloc __a)
: _Base_type(static_cast<_Tp*>(0), _Sp_destroy_inplace<_Tp>(), __a)
, _M_storage()
{ }
template<typename _Ptr>
+ explicit
__shared_count(_Ptr __p) : _M_pi(0)
{
__try
#if _GLIBCXX_DEPRECATED
// Special case for auto_ptr<_Tp> to provide the strong guarantee.
template<typename _Tp>
+ explicit
__shared_count(std::auto_ptr<_Tp>&& __r)
: _M_pi(new _Sp_counted_ptr<_Tp*, _Lp>(__r.get()))
{ __r.release(); }
// Special case for unique_ptr<_Tp,_Del> to provide the strong guarantee.
template<typename _Tp, typename _Del>
+ explicit
__shared_count(std::unique_ptr<_Tp, _Del>&& __r)
: _M_pi(_S_create_from_up(std::move(__r)))
{ __r.release(); }
explicit __shared_ptr(_Tp1* __p) : _M_ptr(__p), _M_refcount(__p)
{
__glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>)
- // __glibcxx_function_requires(_CompleteConcept<_Tp1*>)
+ static_assert( sizeof(_Tp1) > 0, "incomplete type" );
__enable_shared_from_this_helper(_M_refcount, __p, __p);
}
__enable_shared_from_this_helper(_M_refcount, __p, __p);
}
+ template<typename _Deleter>
+ __shared_ptr(nullptr_t __p, _Deleter __d)
+ : _M_ptr(0), _M_refcount(__p, __d)
+ { }
+
+ template<typename _Deleter, typename _Alloc>
+ __shared_ptr(nullptr_t __p, _Deleter __d, const _Alloc& __a)
+ : _M_ptr(0), _M_refcount(__p, __d, __a)
+ { }
+
template<typename _Tp1>
__shared_ptr(const __shared_ptr<_Tp1, _Lp>& __r, _Tp* __p)
: _M_ptr(__p), _M_refcount(__r._M_refcount) // never throws
: _M_ptr(__r.get()), _M_refcount()
{
__glibcxx_function_requires(_ConvertibleConcept<_Tp1*, _Tp*>)
- // TODO requires _Tp1 is complete, delete __r.release() well-formed
+ static_assert( sizeof(_Tp1) > 0, "incomplete type" );
_Tp1* __tmp = __r.get();
_M_refcount = __shared_count<_Lp>(std::move(__r));
__enable_shared_from_this_helper(_M_refcount, __tmp, __tmp);
}
#endif
+ /* TODO: use delegating constructor */
+ __shared_ptr(nullptr_t) : _M_ptr(0), _M_refcount() // never throws
+ { }
+
template<typename _Tp1>
__shared_ptr&
operator=(const __shared_ptr<_Tp1, _Lp>& __r) // never throws
std::forward<_Args>(__args)...);
}
+ /// std::hash specialization for __shared_ptr.
+ template<typename _Tp, _Lock_policy _Lp>
+ struct hash<__shared_ptr<_Tp, _Lp>>
+ : public std::unary_function<__shared_ptr<_Tp, _Lp>, size_t>
+ {
+ size_t
+ operator()(const __shared_ptr<_Tp, _Lp>& __s) const
+ { return std::hash<_Tp*>()(__s.get()); }
+ };
+
_GLIBCXX_END_NAMESPACE
#endif // _SHARED_PTR_BASE_H