Commit efa9d8ee by Jonathan Wakely Committed by Jonathan Wakely

Improve smart pointer docs

	* include/bits/shared_ptr.h: Improve docs.
	* include/bits/shared_ptr_atomic.h: Likewise.
	* include/bits/unique_ptr.h: Likewise. Adjust whitespace.

From-SVN: r270825
parent c4cb56a1
2019-05-02 Jonathan Wakely <jwakely@redhat.com> 2019-05-02 Jonathan Wakely <jwakely@redhat.com>
* include/bits/shared_ptr.h: Improve docs.
* include/bits/shared_ptr_atomic.h: Likewise.
* include/bits/unique_ptr.h: Likewise. Adjust whitespace.
* include/bits/basic_string.h: Fix iterator/index confusion in * include/bits/basic_string.h: Fix iterator/index confusion in
Doxygen comments. Doxygen comments.
* include/bits/range_access.h: Fix Doxygen warnings. * include/bits/range_access.h: Fix Doxygen warnings.
......
...@@ -82,6 +82,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -82,6 +82,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
} }
/// 20.7.2.2.10 shared_ptr get_deleter /// 20.7.2.2.10 shared_ptr get_deleter
/// @relates shared_ptr
template<typename _Del, typename _Tp> template<typename _Del, typename _Tp>
inline _Del* inline _Del*
get_deleter(const shared_ptr<_Tp>& __p) noexcept get_deleter(const shared_ptr<_Tp>& __p) noexcept
...@@ -96,8 +97,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -96,8 +97,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
/** /**
* @brief A smart pointer with reference-counted copy semantics. * @brief A smart pointer with reference-counted copy semantics.
* *
* The object pointed to is deleted when the last shared_ptr pointing to * A `shared_ptr` object is either empty or _owns_ a pointer passed
* it is destroyed or reset. * 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> template<typename _Tp>
class shared_ptr : public __shared_ptr<_Tp> class shared_ptr : public __shared_ptr<_Tp>
...@@ -370,6 +378,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -370,6 +378,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
friend class weak_ptr<_Tp>; friend class weak_ptr<_Tp>;
}; };
/// @relates shared_ptr @{
#if __cpp_deduction_guides >= 201606 #if __cpp_deduction_guides >= 201606
template<typename _Tp> template<typename _Tp>
shared_ptr(weak_ptr<_Tp>) -> shared_ptr<_Tp>; shared_ptr(weak_ptr<_Tp>) -> shared_ptr<_Tp>;
...@@ -480,12 +490,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -480,12 +490,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ return !(nullptr < __a); } { return !(nullptr < __a); }
// 20.7.2.2.8 shared_ptr specialized algorithms. // 20.7.2.2.8 shared_ptr specialized algorithms.
/// Swap overload for shared_ptr
template<typename _Tp> template<typename _Tp>
inline void inline void
swap(shared_ptr<_Tp>& __a, shared_ptr<_Tp>& __b) noexcept swap(shared_ptr<_Tp>& __a, shared_ptr<_Tp>& __b) noexcept
{ __a.swap(__b); } { __a.swap(__b); }
// 20.7.2.2.9 shared_ptr casts. // 20.7.2.2.9 shared_ptr casts.
/// Convert type of `shared_ptr`, via `static_cast`
template<typename _Tp, typename _Up> template<typename _Tp, typename _Up>
inline shared_ptr<_Tp> inline shared_ptr<_Tp>
static_pointer_cast(const shared_ptr<_Up>& __r) noexcept static_pointer_cast(const shared_ptr<_Up>& __r) noexcept
...@@ -494,6 +506,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -494,6 +506,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return _Sp(__r, static_cast<typename _Sp::element_type*>(__r.get())); return _Sp(__r, static_cast<typename _Sp::element_type*>(__r.get()));
} }
/// Convert type of `shared_ptr`, via `const_cast`
template<typename _Tp, typename _Up> template<typename _Tp, typename _Up>
inline shared_ptr<_Tp> inline shared_ptr<_Tp>
const_pointer_cast(const shared_ptr<_Up>& __r) noexcept const_pointer_cast(const shared_ptr<_Up>& __r) noexcept
...@@ -502,6 +515,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -502,6 +515,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return _Sp(__r, const_cast<typename _Sp::element_type*>(__r.get())); return _Sp(__r, const_cast<typename _Sp::element_type*>(__r.get()));
} }
/// Convert type of `shared_ptr`, via `dynamic_cast`
template<typename _Tp, typename _Up> template<typename _Tp, typename _Up>
inline shared_ptr<_Tp> inline shared_ptr<_Tp>
dynamic_pointer_cast(const shared_ptr<_Up>& __r) noexcept dynamic_pointer_cast(const shared_ptr<_Up>& __r) noexcept
...@@ -512,7 +526,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -512,7 +526,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return _Sp(); return _Sp();
} }
#if __cplusplus > 201402L #if __cplusplus >= 201703L
/// Convert type of `shared_ptr`, via `reinterpret_cast`
template<typename _Tp, typename _Up> template<typename _Tp, typename _Up>
inline shared_ptr<_Tp> inline shared_ptr<_Tp>
reinterpret_pointer_cast(const shared_ptr<_Up>& __r) noexcept reinterpret_pointer_cast(const shared_ptr<_Up>& __r) noexcept
...@@ -522,6 +537,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -522,6 +537,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
} }
#endif #endif
// @}
/** /**
* @brief A smart pointer with weak semantics. * @brief A smart pointer with weak semantics.
* *
...@@ -601,6 +618,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -601,6 +618,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
#endif #endif
// 20.7.2.3.6 weak_ptr specialized algorithms. // 20.7.2.3.6 weak_ptr specialized algorithms.
/// Swap overload for weak_ptr
/// @relates weak_ptr
template<typename _Tp> template<typename _Tp>
inline void inline void
swap(weak_ptr<_Tp>& __a, weak_ptr<_Tp>& __b) noexcept swap(weak_ptr<_Tp>& __a, weak_ptr<_Tp>& __b) noexcept
...@@ -617,12 +636,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -617,12 +636,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ }; { };
/// Partial specialization of owner_less for shared_ptr. /// Partial specialization of owner_less for shared_ptr.
/// @relates shared_ptr
template<typename _Tp> template<typename _Tp>
struct owner_less<shared_ptr<_Tp>> struct owner_less<shared_ptr<_Tp>>
: public _Sp_owner_less<shared_ptr<_Tp>, weak_ptr<_Tp>> : public _Sp_owner_less<shared_ptr<_Tp>, weak_ptr<_Tp>>
{ }; { };
/// Partial specialization of owner_less for weak_ptr. /// Partial specialization of owner_less for weak_ptr.
/// @relates weak_ptr
template<typename _Tp> template<typename _Tp>
struct owner_less<weak_ptr<_Tp>> struct owner_less<weak_ptr<_Tp>>
: public _Sp_owner_less<weak_ptr<_Tp>, shared_ptr<_Tp>> : public _Sp_owner_less<weak_ptr<_Tp>, shared_ptr<_Tp>>
...@@ -683,6 +704,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -683,6 +704,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
mutable weak_ptr<_Tp> _M_weak_this; mutable weak_ptr<_Tp> _M_weak_this;
}; };
/// @relates unique_ptr @{
/** /**
* @brief Create an object that is owned by a shared_ptr. * @brief Create an object that is owned by a shared_ptr.
* @param __a An allocator. * @param __a An allocator.
...@@ -730,6 +753,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -730,6 +753,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
} }
}; };
// @} relates shared_ptr
// @} group pointer_abstractions // @} group pointer_abstractions
#if __cplusplus >= 201703L #if __cplusplus >= 201703L
......
...@@ -40,6 +40,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -40,6 +40,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @addtogroup pointer_abstractions * @addtogroup pointer_abstractions
* @{ * @{
*/ */
/// @relates shared_ptr @{
/// @cond undocumented
struct _Sp_locker struct _Sp_locker
{ {
...@@ -60,6 +63,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -60,6 +63,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
#endif #endif
}; };
/// @endcond
/** /**
* @brief Report whether shared_ptr atomic operations are lock-free. * @brief Report whether shared_ptr atomic operations are lock-free.
* @param __p A non-null pointer to a shared_ptr object. * @param __p A non-null pointer to a shared_ptr object.
...@@ -322,6 +327,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -322,6 +327,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
} }
// @} // @}
// @} relates shared_ptr
// @} group pointer_abstractions // @} group pointer_abstractions
_GLIBCXX_END_NAMESPACE_VERSION _GLIBCXX_END_NAMESPACE_VERSION
......
...@@ -686,6 +686,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -686,6 +686,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
unique_ptr& operator=(const unique_ptr&) = delete; unique_ptr& operator=(const unique_ptr&) = delete;
}; };
/// @relates unique_ptr @{
template<typename _Tp, typename _Dp> template<typename _Tp, typename _Dp>
inline inline
#if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11 #if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11
...@@ -754,14 +756,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -754,14 +756,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Tp, typename _Dp> template<typename _Tp, typename _Dp>
_GLIBCXX_NODISCARD inline bool _GLIBCXX_NODISCARD inline bool
operator<(const unique_ptr<_Tp, _Dp>& __x, nullptr_t) 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> template<typename _Tp, typename _Dp>
_GLIBCXX_NODISCARD inline bool _GLIBCXX_NODISCARD inline bool
operator<(nullptr_t, const unique_ptr<_Tp, _Dp>& __x) 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, template<typename _Tp, typename _Dp,
typename _Up, typename _Ep> typename _Up, typename _Ep>
...@@ -790,14 +796,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -790,14 +796,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Tp, typename _Dp> template<typename _Tp, typename _Dp>
_GLIBCXX_NODISCARD inline bool _GLIBCXX_NODISCARD inline bool
operator>(const unique_ptr<_Tp, _Dp>& __x, nullptr_t) 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> template<typename _Tp, typename _Dp>
_GLIBCXX_NODISCARD inline bool _GLIBCXX_NODISCARD inline bool
operator>(nullptr_t, const unique_ptr<_Tp, _Dp>& __x) 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, template<typename _Tp, typename _Dp,
typename _Up, typename _Ep> typename _Up, typename _Ep>
...@@ -834,6 +844,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -834,6 +844,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
#define __cpp_lib_make_unique 201304 #define __cpp_lib_make_unique 201304
/// @cond undocumented
template<typename _Tp> template<typename _Tp>
struct _MakeUniq struct _MakeUniq
{ typedef unique_ptr<_Tp> __single_object; }; { typedef unique_ptr<_Tp> __single_object; };
...@@ -846,6 +858,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -846,6 +858,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
struct _MakeUniq<_Tp[_Bound]> struct _MakeUniq<_Tp[_Bound]>
{ struct __invalid_type { }; }; { struct __invalid_type { }; };
/// @endcond
/// std::make_unique for single objects /// std::make_unique for single objects
template<typename _Tp, typename... _Args> template<typename _Tp, typename... _Args>
inline typename _MakeUniq<_Tp>::__single_object inline typename _MakeUniq<_Tp>::__single_object
...@@ -864,6 +878,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -864,6 +878,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
make_unique(_Args&&...) = delete; make_unique(_Args&&...) = delete;
#endif #endif
// @} relates unique_ptr
// @} group pointer_abstractions // @} group pointer_abstractions
#if __cplusplus >= 201703L #if __cplusplus >= 201703L
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment