31#define _PTR_TRAITS_H 1
33#if __cplusplus >= 201103L
37#if __cplusplus > 201703L
39namespace __gnu_debug {
struct _Safe_iterator_base; }
42namespace std _GLIBCXX_VISIBILITY(default)
44_GLIBCXX_BEGIN_NAMESPACE_VERSION
52 template<
typename _Tp>
53 struct __get_first_arg
54 {
using type = __undefined; };
56 template<
template<
typename,
typename...>
class _SomeTemplate,
typename _Tp,
58 struct __get_first_arg<_SomeTemplate<_Tp, _Types...>>
59 {
using type = _Tp; };
63 template<
typename _Tp,
typename _Up>
64 struct __replace_first_arg
67 template<
template<
typename,
typename...>
class _SomeTemplate,
typename _Up,
68 typename _Tp,
typename... _Types>
69 struct __replace_first_arg<_SomeTemplate<_Tp, _Types...>, _Up>
70 {
using type = _SomeTemplate<_Up, _Types...>; };
73 template<
typename _Ptr,
typename =
void>
74 struct __ptr_traits_elem : __get_first_arg<_Ptr>
79 template<
typename _Ptr>
requires requires {
typename _Ptr::element_type; }
80 struct __ptr_traits_elem<_Ptr, void>
81 {
using type =
typename _Ptr::element_type; };
83 template<
typename _Ptr>
84 struct __ptr_traits_elem<_Ptr, __void_t<typename _Ptr::element_type>>
85 {
using type =
typename _Ptr::element_type; };
88 template<
typename _Ptr>
89 using __ptr_traits_elem_t =
typename __ptr_traits_elem<_Ptr>::type;
94 template<typename _Ptr, typename _Elt, bool = is_void<_Elt>::value>
95 struct __ptr_traits_ptr_to
98 using element_type = _Elt;
107 pointer_to(element_type& __r)
108#if __cpp_lib_concepts
110 { pointer::pointer_to(__r) } -> convertible_to<pointer>;
113 {
return pointer::pointer_to(__r); }
117 template<
typename _Ptr,
typename _Elt>
118 struct __ptr_traits_ptr_to<_Ptr, _Elt, true>
122 template<
typename _Tp>
123 struct __ptr_traits_ptr_to<_Tp*, _Tp,
false>
125 using pointer = _Tp*;
126 using element_type = _Tp;
133 static _GLIBCXX20_CONSTEXPR pointer
134 pointer_to(element_type& __r)
noexcept
138 template<
typename _Ptr,
typename _Elt>
139 struct __ptr_traits_impl : __ptr_traits_ptr_to<_Ptr, _Elt>
142 template<
typename _Tp>
143 using __diff_t =
typename _Tp::difference_type;
145 template<
typename _Tp,
typename _Up>
146 using __rebind = __type_identity<typename _Tp::template rebind<_Up>>;
150 using pointer = _Ptr;
153 using element_type = _Elt;
156 using difference_type = __detected_or_t<ptrdiff_t, __diff_t, _Ptr>;
159 template<
typename _Up>
160 using rebind =
typename __detected_or_t<__replace_first_arg<_Ptr, _Up>,
161 __rebind, _Ptr, _Up>::type;
166 template<
typename _Ptr>
167 struct __ptr_traits_impl<_Ptr, __undefined>
176 template<
typename _Ptr>
186 template<
typename _Tp>
196 template<
typename _Up>
using rebind = _Up*;
200 template<
typename _Ptr,
typename _Tp>
203#ifndef __glibcxx_to_address
204 template<
typename _Tp>
205 [[__gnu__::__always_inline__]]
207 __to_address(_Tp* __ptr)
noexcept
210 "must not be a function pointer");
214 template<
typename _Ptr>
215 constexpr typename std::pointer_traits<_Ptr>::element_type*
216 __to_address(
const _Ptr& __ptr)
217 {
return std::__to_address(__ptr.operator->()); }
225 template<
typename _Tp>
226 [[__gnu__::__always_inline__]]
230 static_assert(!is_function_v<_Tp>,
"std::to_address argument "
231 "must not be a function pointer");
242 template<
typename _Ptr>
248 else if constexpr (is_base_of_v<__gnu_debug::_Safe_iterator_base, _Ptr>)
256 template<
typename _Ptr>
257 [[__gnu__::__always_inline__]]
259 __to_address(
const _Ptr& __ptr)
noexcept
264_GLIBCXX_END_NAMESPACE_VERSION
constexpr _Tp * to_address(_Tp *__ptr) noexcept
Obtain address referenced by a pointer to an object.
constexpr _Tp * addressof(_Tp &__r) noexcept
Returns the actual address of the object or function referenced by r, even in the presence of an over...
ISO C++ entities toplevel namespace is std.
typename pointer_traits< _Ptr >::template rebind< _Tp > __ptr_rebind
Convenience alias for rebinding pointers.
GNU debug classes for public use.
Uniform interface to all pointer-like types.
_Tp * pointer
The pointer type.
ptrdiff_t difference_type
Type used to represent the difference between two pointers.
_Tp element_type
The type pointed to.
_Up * rebind
A pointer to a different type.