}
/// 20.7.2.2.10 shared_ptr get_deleter
+ /// @relates shared_ptr
template<typename _Del, typename _Tp>
inline _Del*
get_deleter(const shared_ptr<_Tp>& __p) noexcept
/**
* @brief A smart pointer with reference-counted copy semantics.
*
- * The object pointed to is deleted when the last shared_ptr pointing to
- * it is destroyed or reset.
+ * A `shared_ptr` object is either empty or _owns_ a pointer passed
+ * to the constructor. Copies of a `shared_ptr` share ownership of
+ * the same pointer. When the last `shared_ptr` that owns the pointer
+ * is destroyed or reset, the owned pointer is freed (either by `delete`
+ * or by invoking a custom deleter that was passed to the constructor).
+ *
+ * A `shared_ptr` also stores another pointer, which is usually
+ * (but not always) the same pointer as it owns. The stored pointer
+ * can be retrieved by calling the `get()` member function.
*/
template<typename _Tp>
class shared_ptr : public __shared_ptr<_Tp>
friend class weak_ptr<_Tp>;
};
+ /// @relates shared_ptr @{
+
#if __cpp_deduction_guides >= 201606
template<typename _Tp>
shared_ptr(weak_ptr<_Tp>) -> shared_ptr<_Tp>;
{ return !(nullptr < __a); }
// 20.7.2.2.8 shared_ptr specialized algorithms.
+ /// Swap overload for shared_ptr
template<typename _Tp>
inline void
swap(shared_ptr<_Tp>& __a, shared_ptr<_Tp>& __b) noexcept
{ __a.swap(__b); }
// 20.7.2.2.9 shared_ptr casts.
+ /// Convert type of `shared_ptr`, via `static_cast`
template<typename _Tp, typename _Up>
inline shared_ptr<_Tp>
static_pointer_cast(const shared_ptr<_Up>& __r) noexcept
return _Sp(__r, static_cast<typename _Sp::element_type*>(__r.get()));
}
+ /// Convert type of `shared_ptr`, via `const_cast`
template<typename _Tp, typename _Up>
inline shared_ptr<_Tp>
const_pointer_cast(const shared_ptr<_Up>& __r) noexcept
return _Sp(__r, const_cast<typename _Sp::element_type*>(__r.get()));
}
+ /// Convert type of `shared_ptr`, via `dynamic_cast`
template<typename _Tp, typename _Up>
inline shared_ptr<_Tp>
dynamic_pointer_cast(const shared_ptr<_Up>& __r) noexcept
return _Sp();
}
-#if __cplusplus > 201402L
+#if __cplusplus >= 201703L
+ /// Convert type of `shared_ptr`, via `reinterpret_cast`
template<typename _Tp, typename _Up>
inline shared_ptr<_Tp>
reinterpret_pointer_cast(const shared_ptr<_Up>& __r) noexcept
}
#endif
+ // @}
+
/**
* @brief A smart pointer with weak semantics.
*
#endif
// 20.7.2.3.6 weak_ptr specialized algorithms.
+ /// Swap overload for weak_ptr
+ /// @relates weak_ptr
template<typename _Tp>
inline void
swap(weak_ptr<_Tp>& __a, weak_ptr<_Tp>& __b) noexcept
{ };
/// Partial specialization of owner_less for shared_ptr.
+ /// @relates shared_ptr
template<typename _Tp>
struct owner_less<shared_ptr<_Tp>>
: public _Sp_owner_less<shared_ptr<_Tp>, weak_ptr<_Tp>>
{ };
/// Partial specialization of owner_less for weak_ptr.
+ /// @relates weak_ptr
template<typename _Tp>
struct owner_less<weak_ptr<_Tp>>
: public _Sp_owner_less<weak_ptr<_Tp>, shared_ptr<_Tp>>
mutable weak_ptr<_Tp> _M_weak_this;
};
+ /// @relates unique_ptr @{
+
/**
* @brief Create an object that is owned by a shared_ptr.
* @param __a An allocator.
}
};
+ // @} relates shared_ptr
// @} group pointer_abstractions
#if __cplusplus >= 201703L
unique_ptr& operator=(const unique_ptr&) = delete;
};
+ /// @relates unique_ptr @{
+
template<typename _Tp, typename _Dp>
inline
#if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11
template<typename _Tp, typename _Dp>
_GLIBCXX_NODISCARD inline bool
operator<(const unique_ptr<_Tp, _Dp>& __x, nullptr_t)
- { return std::less<typename unique_ptr<_Tp, _Dp>::pointer>()(__x.get(),
- nullptr); }
+ {
+ return std::less<typename unique_ptr<_Tp, _Dp>::pointer>()(__x.get(),
+ nullptr);
+ }
template<typename _Tp, typename _Dp>
_GLIBCXX_NODISCARD inline bool
operator<(nullptr_t, const unique_ptr<_Tp, _Dp>& __x)
- { return std::less<typename unique_ptr<_Tp, _Dp>::pointer>()(nullptr,
- __x.get()); }
+ {
+ return std::less<typename unique_ptr<_Tp, _Dp>::pointer>()(nullptr,
+ __x.get());
+ }
template<typename _Tp, typename _Dp,
typename _Up, typename _Ep>
template<typename _Tp, typename _Dp>
_GLIBCXX_NODISCARD inline bool
operator>(const unique_ptr<_Tp, _Dp>& __x, nullptr_t)
- { return std::less<typename unique_ptr<_Tp, _Dp>::pointer>()(nullptr,
- __x.get()); }
+ {
+ return std::less<typename unique_ptr<_Tp, _Dp>::pointer>()(nullptr,
+ __x.get());
+ }
template<typename _Tp, typename _Dp>
_GLIBCXX_NODISCARD inline bool
operator>(nullptr_t, const unique_ptr<_Tp, _Dp>& __x)
- { return std::less<typename unique_ptr<_Tp, _Dp>::pointer>()(__x.get(),
- nullptr); }
+ {
+ return std::less<typename unique_ptr<_Tp, _Dp>::pointer>()(__x.get(),
+ nullptr);
+ }
template<typename _Tp, typename _Dp,
typename _Up, typename _Ep>
#define __cpp_lib_make_unique 201304
+ /// @cond undocumented
+
template<typename _Tp>
struct _MakeUniq
{ typedef unique_ptr<_Tp> __single_object; };
struct _MakeUniq<_Tp[_Bound]>
{ struct __invalid_type { }; };
+ /// @endcond
+
/// std::make_unique for single objects
template<typename _Tp, typename... _Args>
inline typename _MakeUniq<_Tp>::__single_object
make_unique(_Args&&...) = delete;
#endif
+ // @} relates unique_ptr
// @} group pointer_abstractions
#if __cplusplus >= 201703L