diff options
Diffstat (limited to 'libstdc++-v3/include/bits/shared_ptr.h')
-rw-r--r-- | libstdc++-v3/include/bits/shared_ptr.h | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/libstdc++-v3/include/bits/shared_ptr.h b/libstdc++-v3/include/bits/shared_ptr.h index 5e1960012c9..4f87dd459cf 100644 --- a/libstdc++-v3/include/bits/shared_ptr.h +++ b/libstdc++-v3/include/bits/shared_ptr.h @@ -123,6 +123,23 @@ _GLIBCXX_BEGIN_NAMESPACE(std) shared_ptr(_Tp1* __p, _Deleter __d) : __shared_ptr<_Tp>(__p, __d) { } /** + * @brief Construct a %shared_ptr that owns a null pointer + * and the deleter @a __d. + * @param __p A null pointer constant. + * @param __d A deleter. + * @post use_count() == 1 && get() == __p + * @throw std::bad_alloc, in which case @a __d(__p) is called. + * + * Requirements: _Deleter's copy constructor and destructor must + * not throw + * + * The last owner will call __d(__p) + */ + template<typename _Deleter> + shared_ptr(nullptr_t __p, _Deleter __d) + : __shared_ptr<_Tp>(__p, __d) { } + + /** * @brief Construct a %shared_ptr that owns the pointer @a __p * and the deleter @a __d. * @param __p A pointer. @@ -141,6 +158,25 @@ _GLIBCXX_BEGIN_NAMESPACE(std) shared_ptr(_Tp1* __p, _Deleter __d, const _Alloc& __a) : __shared_ptr<_Tp>(__p, __d, __a) { } + /** + * @brief Construct a %shared_ptr that owns a null pointer + * and the deleter @a __d. + * @param __p A null pointer constant. + * @param __d A deleter. + * @param __a An allocator. + * @post use_count() == 1 && get() == __p + * @throw std::bad_alloc, in which case @a __d(__p) is called. + * + * Requirements: _Deleter's copy constructor and destructor must + * not throw _Alloc's copy constructor and destructor must not + * throw. + * + * The last owner will call __d(__p) + */ + template<typename _Deleter, typename _Alloc> + shared_ptr(nullptr_t __p, _Deleter __d, const _Alloc& __a) + : __shared_ptr<_Tp>(__p, __d, __a) { } + // Aliasing constructor /** @@ -212,6 +248,13 @@ _GLIBCXX_BEGIN_NAMESPACE(std) shared_ptr(std::unique_ptr<_Tp1, _Del>&& __r) : __shared_ptr<_Tp>(std::move(__r)) { } + /** + * @brief Construct an empty %shared_ptr. + * @param __p A null pointer constant. + * @post use_count() == 0 && get() == nullptr + */ + shared_ptr(nullptr_t __p) : __shared_ptr<_Tp>(__p) { } + template<typename _Tp1> shared_ptr& operator=(const shared_ptr<_Tp1>& __r) // never throws @@ -471,6 +514,16 @@ _GLIBCXX_BEGIN_NAMESPACE(std) std::forward<_Args>(__args)...); } + /// std::hash specialization for shared_ptr. + template<typename _Tp> + struct hash<shared_ptr<_Tp>> + : public std::unary_function<shared_ptr<_Tp>, size_t> + { + size_t + operator()(const shared_ptr<_Tp>& __s) const + { return std::hash<_Tp*>()(__s.get()); } + }; + // @} group pointer_abstractions _GLIBCXX_END_NAMESPACE |