Commit c05ab418 by Jonathan Wakely Committed by Jonathan Wakely

Improve API docs for <memory> and <scoped_allocator>

	* config/allocator/new_allocator_base.h (__allocator_base): Add
	workaround for Doxygen bug #6945.
	* include/std/memory: Improve docs. Define group for pointer safety.
	* include/std/scoped_allocator: Improve docs. Use "undocumented"
	conditional to suppress documentation for implementation details.

From-SVN: r270807
parent d16250de
2019-05-02 Jonathan Wakely <jwakely@redhat.com> 2019-05-02 Jonathan Wakely <jwakely@redhat.com>
* config/allocator/new_allocator_base.h (__allocator_base): Add
workaround for Doxygen bug #6945.
* include/std/memory: Improve docs. Define group for pointer safety.
* include/std/scoped_allocator: Improve docs. Use "undocumented"
conditional to suppress documentation for implementation details.
* include/bits/specfun.h: Improve docs. * include/bits/specfun.h: Improve docs.
* include/tr1/cmath: Likewise. Fix nesting of preprocessor conditions * include/tr1/cmath: Likewise. Fix nesting of preprocessor conditions
and namespaces. and namespaces.
......
...@@ -37,11 +37,11 @@ namespace std ...@@ -37,11 +37,11 @@ namespace std
{ {
/** /**
* @brief An alias to the base class for std::allocator. * @brief An alias to the base class for std::allocator.
* @ingroup allocators
* *
* Used to set the std::allocator base class to * Used to set the std::allocator base class to
* __gnu_cxx::new_allocator. * __gnu_cxx::new_allocator.
* *
* @ingroup allocators
* @tparam _Tp Type of allocated object. * @tparam _Tp Type of allocated object.
*/ */
template<typename _Tp> template<typename _Tp>
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
/** @file include/memory /** @file include/memory
* This is a Standard C++ Library header. * This is a Standard C++ Library header.
* @ingroup memory
*/ */
#ifndef _GLIBCXX_MEMORY #ifndef _GLIBCXX_MEMORY
...@@ -100,19 +101,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -100,19 +101,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
/** /**
* @brief Fit aligned storage in buffer. * @brief Fit aligned storage in buffer.
* * @ingroup memory
* [ptr.align]
* *
* This function tries to fit @a __size bytes of storage with alignment * This function tries to fit @a __size bytes of storage with alignment
* @a __align into the buffer @a __ptr of size @a __space bytes. If such * @a __align into the buffer @a __ptr of size @a __space bytes. If such
* a buffer fits then @a __ptr is changed to point to the first byte of the * a buffer fits then @a __ptr is changed to point to the first byte of the
* aligned storage and @a __space is reduced by the bytes used for alignment. * aligned storage and @a __space is reduced by the bytes used for alignment.
* *
* C++11 20.6.5 [ptr.align]
*
* @param __align A fundamental or extended alignment value. * @param __align A fundamental or extended alignment value.
* @param __size Size of the aligned storage required. * @param __size Size of the aligned storage required.
* @param __ptr Pointer to a buffer of @a __space bytes. * @param __ptr Pointer to a buffer of @a __space bytes.
* @param __space Size of the buffer pointed to by @a __ptr. * @param __space Size of the buffer pointed to by @a __ptr.
* @return the updated pointer if the aligned storage fits, otherwise nullptr. * @return the updated pointer if the aligned storage fits, otherwise nullptr.
*
*/ */
inline void* inline void*
align(size_t __align, size_t __size, void*& __ptr, size_t& __space) noexcept align(size_t __align, size_t __size, void*& __ptr, size_t& __space) noexcept
...@@ -136,28 +139,52 @@ align(size_t __align, size_t __size, void*& __ptr, size_t& __space) noexcept ...@@ -136,28 +139,52 @@ align(size_t __align, size_t __size, void*& __ptr, size_t& __space) noexcept
} }
} }
// 20.7.4 [util.dynamic.safety], pointer safety /** @defgroup ptr_safety Pointer Safety and Garbage Collection
* @ingroup memory
*
* Utilities to assist with garbage collection in an implementation
* that supports <em>strict pointer safety</em>.
* This implementation only supports <em>relaxed pointer safety</em>
* and so these functions have no effect.
*
* C++11 20.6.4 [util.dynamic.safety], Pointer safety
*
* @{
*/
/// Constants representing the different types of pointer safety.
enum class pointer_safety { relaxed, preferred, strict }; enum class pointer_safety { relaxed, preferred, strict };
/// Inform a garbage collector that an object is still in use.
inline void inline void
declare_reachable(void*) { } declare_reachable(void*) { }
/// Unregister an object previously registered with declare_reachable.
template <typename _Tp> template <typename _Tp>
inline _Tp* inline _Tp*
undeclare_reachable(_Tp* __p) { return __p; } undeclare_reachable(_Tp* __p) { return __p; }
/// Inform a garbage collector that a region of memory need not be traced.
inline void inline void
declare_no_pointers(char*, size_t) { } declare_no_pointers(char*, size_t) { }
/// Unregister a range previously registered with declare_no_pointers.
inline void inline void
undeclare_no_pointers(char*, size_t) { } undeclare_no_pointers(char*, size_t) { }
/// The type of pointer safety supported by the implementation.
inline pointer_safety inline pointer_safety
get_pointer_safety() noexcept { return pointer_safety::relaxed; } get_pointer_safety() noexcept { return pointer_safety::relaxed; }
// @}
#if __cplusplus > 201703L #if __cplusplus > 201703L
/// Inform the compiler that a pointer is aligned. /** @brief Inform the compiler that a pointer is aligned.
*
* @tparam _Align An alignment value (i.e. a power of two)
* @tparam _Tp An object type
* @param __ptr A pointer that is aligned to _Align
* @ingroup memory
*/
template<size_t _Align, class _Tp> template<size_t _Align, class _Tp>
[[nodiscard,__gnu__::__always_inline__]] [[nodiscard,__gnu__::__always_inline__]]
constexpr _Tp* assume_aligned(_Tp* __ptr) constexpr _Tp* assume_aligned(_Tp* __ptr)
...@@ -176,6 +203,9 @@ get_pointer_safety() noexcept { return pointer_safety::relaxed; } ...@@ -176,6 +203,9 @@ get_pointer_safety() noexcept { return pointer_safety::relaxed; }
template<typename _Tp, typename _Up> template<typename _Tp, typename _Up>
struct __is_pair<const pair<_Tp, _Up>> : true_type { }; struct __is_pair<const pair<_Tp, _Up>> : true_type { };
/** @addtogroup allocators
* @{
*/
template<typename _Tp, typename __ = _Require<__not_<__is_pair<_Tp>>>, template<typename _Tp, typename __ = _Require<__not_<__is_pair<_Tp>>>,
typename _Alloc, typename... _Args> typename _Alloc, typename... _Args>
constexpr auto constexpr auto
...@@ -358,6 +388,7 @@ get_pointer_safety() noexcept { return pointer_safety::relaxed; } ...@@ -358,6 +388,7 @@ get_pointer_safety() noexcept { return pointer_safety::relaxed; }
return ::new(__vp) _Tp(std::make_obj_using_allocator<_Tp>(__a, return ::new(__vp) _Tp(std::make_obj_using_allocator<_Tp>(__a,
std::forward<_Args>(__args)...)); std::forward<_Args>(__args)...));
} }
// @}
#endif // C++2a #endif // C++2a
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
/** @file include/scoped_allocator /** @file include/scoped_allocator
* This is a Standard C++ Library header. * This is a Standard C++ Library header.
* @ingroup allocators
*/ */
#ifndef _SCOPED_ALLOCATOR #ifndef _SCOPED_ALLOCATOR
...@@ -49,6 +50,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -49,6 +50,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @{ * @{
*/ */
/// @cond undocumented
template<typename _Alloc> template<typename _Alloc>
using __outer_allocator_t using __outer_allocator_t
= decltype(std::declval<_Alloc>().outer_allocator()); = decltype(std::declval<_Alloc>().outer_allocator());
...@@ -75,6 +78,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -75,6 +78,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{ return __base::_S_outermost(__a.outer_allocator()); } { return __base::_S_outermost(__a.outer_allocator()); }
}; };
/// Implementation of the OUTERMOST pseudofunction
template<typename _Alloc> template<typename _Alloc>
inline typename __outermost_type<_Alloc>::type& inline typename __outermost_type<_Alloc>::type&
__outermost(_Alloc& __a) __outermost(_Alloc& __a)
...@@ -164,7 +168,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -164,7 +168,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__type _M_inner; __type _M_inner;
}; };
/// Primary class template. /// @endcond
/// An adaptor to recursively pass an allocator to the objects it constructs
template<typename _OuterAlloc, typename... _InnerAllocs> template<typename _OuterAlloc, typename... _InnerAllocs>
class scoped_allocator_adaptor class scoped_allocator_adaptor
: public _OuterAlloc : public _OuterAlloc
...@@ -484,6 +490,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -484,6 +490,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
#endif // C++17 #endif // C++17
}; };
/// @related std::scoped_allocator_adaptor
template <typename _OutA1, typename _OutA2, typename... _InA> template <typename _OutA1, typename _OutA2, typename... _InA>
inline bool inline bool
operator==(const scoped_allocator_adaptor<_OutA1, _InA...>& __a, operator==(const scoped_allocator_adaptor<_OutA1, _InA...>& __a,
...@@ -493,6 +500,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -493,6 +500,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
&& __a._M_inner == __b._M_inner; && __a._M_inner == __b._M_inner;
} }
/// @related std::scoped_allocator_adaptor
template <typename _OutA1, typename _OutA2, typename... _InA> template <typename _OutA1, typename _OutA2, typename... _InA>
inline bool inline bool
operator!=(const scoped_allocator_adaptor<_OutA1, _InA...>& __a, operator!=(const scoped_allocator_adaptor<_OutA1, _InA...>& __a,
......
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